2010-08-01 36 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」大型圖片

好運更換!