问题描述
我想让我网站上的用户能够将图像上传到他们的帐户.图像将被调整为整个站点所需的4种不同大小.
I want to enable users on my site to upload images to their accounts. The images get resized into 4 different sizes required across the site.
我一直在使用Pear Image_Transform,但在某些类型的jpg(所有尝试在2mb以下的文件)上,我一直遇到字节用尽"的致命错误.因此,我转而使用奔腾双核E5200 @ 2.50GHz和2GB ram的专用服务器.上载了相同的图片调整大小代码-相同的错误.我将php.ini中的RAM升级到64M,但是网站在某些类型的jpg上也遇到了同样的问题.还尝试了wideimage类-同样的错误(imagecreatefromjpeg()始终存在错误). (使用GD2).在我的Mac上本地一切正常.
I have been using Pear Image_Transform but I kept getting "bytes exhausted" fatal errors on certain types of jpgs (all files tried under 2mb). So I moved to a dedicated server with Pentium Dual-Core E5200 @ 2.50GHz and 2GB ram. Uploaded the same image resize code - same error. I upped the RAM in php.ini to 64M but site get the same problem on certain types of jpg. Also tried wideimage class - same error (error is always with imagecreatefromjpeg()). (Using GD2). All works fine locally on my mac.
这真的是一个内存问题吗?对于我的设置+图片大小调整,合理的memory_limit是多少?
Is this really a memory issue, what's a reasonable memory_limit for my set up + image resizing?
推荐答案
可以大致计算出所需内存的粗略指南
A rough guide to how much memory you're going to need can be calculated like this
$imageInfo = getimagesize( $sourceImagePath );
// a check to make sure we have enough memory to hold this image
$requiredMemoryMB = ( $imageInfo[0] * $imageInfo[1] * ($imageInfo['bits'] / 8) * $imageInfo['channels'] * 2.5 ) / 1024;
这很粗糙,其中包含2.5的软糖系数,您可能想尝试一下.
This is quite rough and includes a fudge factor, 2.5, which you may want to experiment with.
这篇关于合理的PHP memory_limit来调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!