[英]PHP GD imagecreatefromjpeg cant handle big size image?
我的项目是当我自动上传图像时,我的程序将创建拇指大小。
我的程序正常工作,如果图片的大小约1024x768但当我上传图像大小1576x2379显示错误,如下所示:
允许的内存大小为8388608字节耗尽(试图分配1576字节)
我正在使用方法imagcreatefromjpeg()。
如何使用PHP从大尺寸图像创建拇指版?
谢谢
你必须编辑你的php.ini
找到具有内存限制语句的行,并更改其更大的默认值 - 例如128M
对我来说,这个问题通过下一代代码来解决:
并安装它作为PHP的一部分(php5-imagick)
我的代码部分(适用于Smart Image Resizer 1.4.1)
我找到了行“$ src = $ creationFunction($ docRoot。$ image);” 并替换为
if ( $width >= 1900 )
{
// Read original image and create Imagick object
$thumb = new Imagick($docRoot . $image);
$newX = 1600;
$newY = 1200;
// Scale the image
$thumb->thumbnailImage($newX,$newY);
#$thumb->cropThumbnailImage(600,600);
// make new file-name
$_ext_pos = strrpos($image,'.');
$_image_name_p1 = substr($image, 0, $_ext_pos);
$_image_name_p2 = substr($image, $_ext_pos);
$thumbnailFilename = $_image_name_p1.'_s600'.$_image_name_p2;
// Write the new image to a file
$thumb->writeImage($docRoot . $thumbnailFilename);
$thumb->destroy();
// Read in the original image
$src = $creationFunction($docRoot . $thumbnailFilename);
// reset w-h
$size = GetImageSize($docRoot . $thumbnailFilename);
$width = $size[0];
$height = $size[1];
// Setting up the ratios needed for resizing.
// resize the image (based on height or based on width)
$xRatio = 1;#$maxWidth / $width;
$yRatio = 1;#$maxHeight / $height;
if ($xRatio * $height < $maxHeight)
{ // Resize the image based on width
$tnHeight = ceil($xRatio * $height);
$tnWidth = $maxWidth;
}
else // Resize the image based on height
{
$tnWidth = ceil($yRatio * $width);
$tnHeight = $maxHeight;
}
}
else
{
// Read in the original image
$src = $creationFunction($docRoot . $image);
}
所以我用imagick-workflow替换了大型图像的“ImageCreateFromJpeg”
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.