I'm designing a website and I need to:
- Upload the image
- Validate that it's an image (and not, oh I don't know.... a virus :) )
- Resize the Image
- convert to jpg
Essentially basic image upload
Instead of writing my own I'm trying to find a php class that let's me do all this, because as Jeff Atwood said, "never design what you can steal"
Now before you go ahead and downvote because I didn't do my research, I did:
Googling this brings up a huge amount of results, which is the problem, I don't know which results are useful and which are trash!
So far, Ive found:
- https://stackoverflow.com/questions/4997127/php-class-to-upload-image-from-url-and-resize-it (I know it looks like a duplicate, but its not because it is asking for a URL fetcher)
- http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/
- http://www.verot.net/php_class_upload.htm
- http://blog.freelancer-id.com/index.php/2010/03/21/php-image-crop-resize-upload
- http://www.phpclasses.org/package/2181-PHP-Process-files-and-images-uploaded-via-a-form.html
- http://www.digitalgemstones.com/code/tools/ImgUploader.php
Does anyone have any experience with these classes? Can you recommend an outstanding image upload class?
there's also this lightweight image manipulation library written in PHP called Zebra_Image that's very small, not bloated with zillion of functions you'll never use, highly optimized, with a great documentation and which is actively maintained.
Check out JCROP Plugin
This will be uselful for all
JCROP Image cropping----deepliquid.com/content/Jcrop.html
My personal favorite Image Manipulation Library is
WideImage
. It makes is ridiculously easy to do that kind of task.As for validating if it is actually an image or not, use
finfo
orPEAR::Mime_type
. I personally preferPEAR::Mime_Type
. It usesfinfo
but it's just simpler to use.Using
finfo
:Using
PEAR::Mime_Type
:If you're willing to migrate into an MVC PHP framework, I strongly recommend Codeigniter.
Besides several other classes and libraries that handle pagination, tables, security, forms, etc CI also has nice upload and image manipulation classes that are very handy and flexible. I believe they can do all you require (just not sure about jpg conversion).
You can check them out at:
Image manipulation class
File uploading class
The class upload from Colin Verot http://www.verot.net/php_class_upload.htm is my favourite. I use in in all my projects. Like the way you 'talk' to the class and only use what your need, but gives plenty of configuration/methods to tweak it to your exact needs. Great class!
I am using this Image crop, it working well
Simple PHP Image cCrop