简体   繁体   中英

PHP Thumbnails

I was looking at a way to dynamically create thumbnails using PHP and GD but everytime i select a large image maybe 10MegaPixels about 4-5MB it gives the error

**images/Surabhi_Cow.jpgimages/tn/Surabhi_Cow.jpg
Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 10368 bytes) in C:\Program Files\xampp\htdocs\MySite\Staff\test.php on line 51**

Changing the memory_limit in php.ini to 60 does the trick but my host only allows the memory_limit to 32M. What other options do I have to generate thumbnails on the fly? I checked phpThumb() but don't really get it. So any other options are welcome!

You want to use ImageMagick . It is much more efficient in handling large images than GD.

If all you want to do is generate thumbnails. I recommend this nice little script called imagethumb.php . You can download it here: http://www.olivo.net/software/imagethumb/

This script produces excellent thumbnails with absolutely no pixelation. It accepts a height or width argument that you append to the URL that calls the script. It's really really easy to use and comes with documentation (which you'll read for all of 2 minutes).

I tried other thumbnailing scripts such as "ThumbsUp" (for example) before landing on this one. BTW, it also renders .png images and also .gif (if I recall correctly). The cache feature will make it easier on your server if you have large files. Also, I assume that your server has the GD library or ImageMagick installed. Good Luck ;)

I was doing some research on the topic and I found Imagick much more efficient for manipulating bigger images. You`ll either pass the allowed memory or the maximum execution time. A better approach would be to use Imagick library. Check the onfo on how to generate thumbnails with php on the fly using Imagick.

Consider using a command-line based approach. For example, you can invoke ImageMagick from the command-line to resize images.

Other than that, in pure PHP, it's hard to see how you can edit images that are larger (in RGB format) than your RAM...

As the others have said, if the images are that big it's time to drop GD and switch to ImageMagick. One word of warning though: do it all on the command-line - the class wrappers out there are wheels in need of damn good re-inventing, every last one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM