简体   繁体   English

PHP缩略图

[英]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 我正在寻找一种使用PHP和GD动态创建缩略图的方法,但每次我选择一个大图像可能是10MegaPixels大约4-5MB它给出错误

**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. 将php.ini中的memory_limit更改为60可以解决问题,但我的主机只允许memory_limit为32M。 What other options do I have to generate thumbnails on the fly? 我还有哪些其他选项可以动态生成缩略图? I checked phpThumb() but don't really get it. 我检查了phpThumb()但是没有真正得到它。 So any other options are welcome! 所以欢迎任何其他选择!

You want to use ImageMagick . 您想使用ImageMagick It is much more efficient in handling large images than GD. 处理大图像比GD更有效。

If all you want to do is generate thumbnails. 如果您只想生成缩略图。 I recommend this nice little script called imagethumb.php . 我推荐这个名为imagethumb.php的小脚本。 You can download it here: http://www.olivo.net/software/imagethumb/ 你可以在这里下载: 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. 它接受您附加到调用脚本的URL的高度或宽度参数。 It's really really easy to use and comes with documentation (which you'll read for all of 2 minutes). 它真的很容易使用,并附带文档(您将在2分钟内阅读)。

I tried other thumbnailing scripts such as "ThumbsUp" (for example) before landing on this one. 在登陆之前我尝试了其他缩略图脚本,例如“ThumbsUp”(例如)。 BTW, it also renders .png images and also .gif (if I recall correctly). 顺便说一句,它还呈现.png图像和.gif(如果我没记错的话)。 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. 另外,我假设您的服务器安装了GD库或ImageMagick Good Luck ;) 祝你好运;)

I was doing some research on the topic and I found Imagick much more efficient for manipulating bigger images. 我正在对这个主题进行一些研究,我发现使用Imagick可以更有效地操作更大的图像。 You`ll either pass the allowed memory or the maximum execution time. 您将传递允许的内存或最长执行时间。 A better approach would be to use Imagick library. 更好的方法是使用Imagick库。 Check the onfo on how to generate thumbnails with php on the fly using Imagick. 使用Imagick检查有关如何使用php动态生成缩略图的 onfo。

Consider using a command-line based approach. 考虑使用基于命令行的方法。 For example, you can invoke ImageMagick from the command-line to resize images. 例如,您可以从命令行调用ImageMagick来调整图像大小。

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... 除此之外,在纯PHP中,很难看出如何编辑比RAM更大的图像( RGB格式)...

As the others have said, if the images are that big it's time to drop GD and switch to ImageMagick. 正如其他人所说的那样,如果图像那么大,就应该放弃GD并切换到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. 但是有一个警告:在命令行上完成所有操作 - 类包装器中有一些轮子需要很好的重新发明,每一个都是最后一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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