I'm designing a website and I need to:
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:
Does anyone have any experience with these classes? Can you recommend an outstanding image upload class?
My personal favorite Image Manipulation Library is WideImage
. It makes is ridiculously easy to do that kind of task.
WideImage::load('pic.png') ->crop('center', 'center', 90, 50)->saveToFile('cropped/pic.jpg');
As for validating if it is actually an image or not, use finfo
or PEAR::Mime_type
. I personally prefer PEAR::Mime_Type
. It uses finfo
but it's just simpler to use.
Using finfo
:
$finfo = finfo_open(FILEINFO_MIME_TYPE); $mimetype = finfo_file($finfo, $filename); $isImage = (preg_match('#^image/#', $mimetype) === 1);
Using PEAR::Mime_Type
:
$mimetype = MIME_Type::autoDetect($filename); $isImage = MIME_Type::wildcardMatch('image/*', $mimetype);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With