我的项目是当我自动上传图像时,我的程序会创建拇指大小。
如果图片大小约为1024x768我的程序正常工作但是当我上传大小为1576x2379的图像时显示如下错误:
允许的内存大小为8388608字节耗尽(尝试分配1576字节)
我正在使用方法imagcreatefromjpeg()。
如何使用PHP从大尺寸图像创建拇指版本???
感谢
答案 0 :(得分:5)
你必须编辑你的php.ini
找到具有内存限制语句的行,并更改其更大值的默认值 - 例如128M
答案 1 :(得分:0)
对我来说,这个问题在下一个代码安静时解决了:
并将其安装为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”
祝你好运!