2010-08-01 39 views
2

我的项目是当我自动上传图片时,我的程序会创建拇指大小。
我的程序正常工作,如果图片的尺寸大约为1024x768但是当我上传的图像大小为1576x2379显示错误是这样的:PHP GD imagecreatefromjpeg无法处理大尺寸图像?

用尽8388608个字节

允许的内存大小(试图分配1576个字节)

我使用方法imagcreatefromjpeg()。
如何使用PHP从大尺寸图像创建拇指版?

感谢

回答

4

你必须编辑php.ini
查找内存限制语句行,更改其默认值更大的东西 - 比如128M

+1

感谢它的作品。它也可以通过ini_set(“memory_limit”,“200M”)在程序中设置。 – user315196 2010-08-01 08:56:52

0

对于我接下来的这个问题很好解决代码安宁:

  1. 首先你需要在你的服务器上安装imagemagick;
  2. 并且也将它安装为PHP的一部分(PHP5-imagick)

  3. 我的代码的一部分(智能图像调整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的工作流程取代“ImageCreateFromJpeg”大型图片

好运更换!