Lowyat.NET Forums

Welcome Guest ( Log In | Register )

 
RSS feedBump TopicReply to this topicStart new topicStart Poll

Outline · [ Standard ] · Linear+

> PHP: Image Manipulator Class, Use it and give me feedback :)

silverhawk
post Jun 14 2006, 11:57 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #1


I'm SHINY~!
Group Icon

Group: Elite
Posts: 3,303
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jan 2003





I just finished writing a class to manipulate images in PHP. It is based on PHP4, so there are some OOP features missing. No private/protected for example... everything is public >_<.

The documentation will detail what is private and what is public. So use them acccordingly smile.gif If you find any bugs, or can suggest any improvements please feel free to tell me.

What you can do with this class:
  • resize images
  • convert to GIF/JPEG/PNG
  • extract a portion of an image
  • flip the image
  • rotate the image
  • add text to the image
  • add a watermark to the image

Supports the following formats:
  • GIF
  • JPEG
  • PNG

Requires:
  • PHP 4.3.2+
  • GD2 with FreeType support

Examples
You may take a look at the list of examples.
*Note: That server does not have FreeType support, so two of the examples won't show*

Documentation
http://hawks-eyrie.net/php/classes/graphic...ator/Image.html

My first try with phpDoc. Anyone with experience wanna teach me how to change the text on the index page?

Download
The zip file contains the class file, examples and documentation.

Hope you people will find this useful smile.gif
User is online!Profile CardPM
Go to the top of the page
+Quote Post
anthony_yio
post Jun 15 2006, 06:51 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #2


........
Group Icon
Codemasters

Group: Elite
Posts: 1,794
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jan 2003





QUOTE(silverhawk @ Jun 14 2006, 11:57 PM)
I just finished writing a class to manipulate images in PHP. It is based on PHP4, so there are some OOP features missing. No private/protected for example... everything is public >_<.

The documentation will detail what is private and what is public. So use them acccordingly smile.gif If you find any bugs, or can suggest any improvements please feel free to tell me.

What you can do with this class:


  • resize images

  • convert to GIF/JPEG/PNG

  • extract a portion of an image

  • flip the image

  • rotate the image

  • add text to the image

  • add a watermark to the image


Supports the following formats:


  • GIF

  • JPEG

  • PNG


Requires:


  • PHP 4.3.2+

  • GD2 with FreeType support


Examples
You may take a look at the list of examples.
*Note: That server does not have FreeType support, so two of the examples won't show*

Documentation
http://hawks-eyrie.net/php/classes/graphic...ator/Image.html

My first try with phpDoc. Anyone with experience wanna teach me how to change the text on the index page?

Download
The zip file contains the class file, examples and documentation.

Hope you people will find this useful smile.gif
*



PHP is not my realm, therefore I can't really comment much. Yet, I would still like to compliment you. Keep up the good work.

This post has been edited by anthony_yio: Jun 15 2006, 06:52 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
nexus-
post Jun 15 2006, 07:42 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #3


The intrepid coward
Group Icon
Retired Forum Administrator

Group: VIP
Posts: 3,744
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jan 2003
From: Sydney, Australia






Your constructor is... interesting.

I noticed that in your entire project you do not take account that your script will be a security vulnerability in the server it runs on. It could potentially reveal file locations where it has access to and even overwrite files by supplying malicious input (e.g. ../../../system32/notepad.exe). It gets worse if a front end author allows the user to upload their own files (e.g. executables). With the ability to change the file extension and arbitrarily choose the location to save it in, you are talking about potential nasty backdoors wink.gif

I believe sanitization should be handled by your class instead of the frontend, since it is a single point of entry (instead of covering all the front ends, cover the backend).

That aside, the formatting of the code is excellent, and the documentation good. I am wondering why didn't you use PHP5, since you already know the OOP abilities of it.

Well, overall I think its not bad.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
silverhawk
post Jun 15 2006, 08:13 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #4


I'm SHINY~!
Group Icon

Group: Elite
Posts: 3,303
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jan 2003





QUOTE(nexus- @ Jun 15 2006, 07:42 PM)
Your constructor is... interesting.

How is it interesting? lol
Sounds like you have something to say smile.gif

QUOTE
I noticed that in your entire project you do not take account that your script will be a security vulnerability in the server it runs on. It could potentially reveal file locations where it has access to and even overwrite files by supplying malicious input (e.g. ../../../system32/notepad.exe). It gets worse if a front end author allows the user to upload their own files (e.g. executables). With the ability to change the file extension and arbitrarily choose the location to save it in, you are talking about potential nasty backdoors wink.gif

I believe sanitization should be handled by your class instead of the frontend, since it is a single point of entry (instead of covering all the front ends, cover the backend).

Well, it is quite safe against malicious uploads. It will only handle GIF/JPEG/PNG files, any other file even with their extension changed will not work. The file data is obtained with the getimagesize() function. The mime-type is obtained from there, if it is a file "application/octet-stream" is returned, that is not within the allowed mime-types.

However you are right on the save path part, i will have to sanitise the input for that to make sure they don't go about overwritting files where they aren't supposed to. Will post an update soon, i also noticed a typo in the doc tongue.gif

QUOTE
That aside, the formatting of the code is excellent, and the documentation good. I am wondering why didn't you use PHP5, since you already know the OOP abilities of it.

On the most part because PHP5 isn't widely adopted on web hosts yet. Have to use what has the largest support, after all this will be used on my client's websites.

QUOTE
Well, overall I think its not bad.
*


Thanks smile.gif
User is online!Profile CardPM
Go to the top of the page
+Quote Post
nexus-
post Jun 15 2006, 08:37 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #5


The intrepid coward
Group Icon
Retired Forum Administrator

Group: VIP
Posts: 3,744
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jan 2003
From: Sydney, Australia






QUOTE(silverhawk @ Jun 15 2006, 10:13 PM)
How is it interesting? lol
Sounds like you have something to say smile.gif
Well, it is quite safe against malicious uploads. It will only handle GIF/JPEG/PNG files, any other file even with their extension changed will not work. The file data is obtained with the getimagesize() function. The mime-type is obtained from there, if it is a file "application/octet-stream" is returned, that is not within the allowed mime-types.

However you are right on the save path part, i will have to sanitise the input for that to make sure they don't go about overwritting files where they aren't supposed to. Will post an update soon, i also noticed a typo in the doc tongue.gif

*


Ah okay, I missed the save() function. I assumed that the file would still be saved to the targetted path even if you returned false in your constructor.

Also, you need to sanitize the input to the constructor so that your script doesn't leak information about a server (e.g. determine if a file exists/does not exist on the server by checking the error message).
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Bump TopicReply to this topicTopic OptionsStart new topic
 



----debug section please ignore----
Lo-Fi Version Time is now: 25th November 2009 - 04:02 PM
All Rights Reserved 2003-2009 Vijandren Ramadass (~living on a prayer~)