1
我有一個功能,將一些圖像複製到畫布上並將其保存到文件中。我的代碼在帖子的底部。如何將大量圖像複製到PHP中的畫布上?
當我嘗試將15圖像複製到畫布上時,代碼正常工作,但是當我嘗試複製30時,它只是停止。沒有錯誤或異常...
我希望你可以幫我:)
$img = imagecreatefromjpeg($image);
$imgWidth = imagesx($img);
$imgHeight = imagesy($img);
// CREATE CANVAS AND FILL WITH WHITE
$canvas = imagecreatetruecolor($guidelines['canvasW'] * $dpi, $guidelines['canvasH'] * $dpi);
$color = imagecolorallocate($canvas, 255, 255, 255);
imagefill($canvas, 0, 0, $color);
// COPY THE IMAGES ONTO THE CANVAS
foreach($guidelines['imageGuide'] as $guide):
$bestFit = bestFit($imgWidth, $imgHeight, $guide['W'] * $dpi, $guide['H'] * $dpi);
if($bestFit['rotate']) {
$output = imagerotate($img, 90, 0);
} else {
$output = imagerotate($img, 0, 0);
}
imagecopyresampled($canvas, $output, $guide['X'] * $dpi, $guide['Y'] * $dpi, 0, 0, $bestFit['x'], $bestFit['y'], imagesx($output), imagesy($output));
imagedestroy($output);
endforeach;
$指引是一個數組。下面是一個將16張圖像複製到畫布上的示例。
$guidelines = array( 'canvasW' => 20,
'canvasH' => 30,
'imageGuide' => array(
array('W' => 18, 'H' => 13, 'X' => 1, 'Y' => 1.5),
array('W' => 3.5, 'H' => 4.5, 'X' => 1.25, 'Y' => 15),
array('W' => 3.5, 'H' => 4.5, 'X' => 4.75, 'Y' => 15),
array('W' => 3.5, 'H' => 4.5, 'X' => 8.25, 'Y' => 15),
array('W' => 3.5, 'H' => 4.5, 'X' => 11.75, 'Y' => 15),
array('W' => 3.5, 'H' => 4.5, 'X' => 15.25, 'Y' => 15),
array('W' => 3.5, 'H' => 4.5, 'X' => 1.25, 'Y' => 19.5),
array('W' => 3.5, 'H' => 4.5, 'X' => 4.75, 'Y' => 19.5),
array('W' => 3.5, 'H' => 4.5, 'X' => 8.25, 'Y' => 19.5),
array('W' => 3.5, 'H' => 4.5, 'X' => 11.75, 'Y' => 19.5),
array('W' => 3.5, 'H' => 4.5, 'X' => 15.25, 'Y' => 19.5),
array('W' => 3.5, 'H' => 4.5, 'X' => 1.25, 'Y' => 24),
array('W' => 3.5, 'H' => 4.5, 'X' => 4.75, 'Y' => 24),
array('W' => 3.5, 'H' => 4.5, 'X' => 8.25, 'Y' => 24),
array('W' => 3.5, 'H' => 4.5, 'X' => 11.75, 'Y' => 24),
array('W' => 3.5, 'H' => 4.5, 'X' => 15.25, 'Y' => 24),
),
);
你有錯誤報告嗎?它通常在這種情況下用完內存... – 2011-01-25 21:44:05
你檢查了你的錯誤日誌,並嘗試把`error_reporting(0)`放在你的應用程序中,應該有一個痕跡 – RobertPitt 2011-01-25 21:45:21