因此,我需要合併一些圖像(36或48)圖像到另一個圖像();在很好的時間合併大量的圖像與PHP GD(imagecopymerge)
這是4800x4800像素的分辨率。所以每個廣場將有695x695;目前,我想出了這個解決方案:
$i = 1;
$x = 140; $y = 140;
foreach($files as $file):
if($i > 1) $template = 'test.png';
else $template = 'templates/24x24-TEMPLATE.png';
$this->save_image($file,'templates/temp.jpg');
$src = imagecreatefromjpeg('templates/temp.jpg');
$src2 = imagecreatetruecolor(695,695);
imagecopyresampled($src2, $src, 0, 0, 0, 0, 695, 695, 612, 612);
imagejpeg($src2,'templates/temp.jpg');
imagedestroy($src2);
$src = imagecreatefromjpeg('templates/temp.jpg');
$dest = imagecreatefrompng($template);
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagealphablending($src, false);
imagesavealpha($src, true);
imagecopymerge($dest, $src, $x, $y, 0, 0, 695, 695, 100); //have to play with these numbers for it to work for you, etc.
imagepng($dest,'test.png');
/* Destroy the images to free up space */
imagedestroy($dest);
imagedestroy($src);
$x = $x + 695 + 65;
if($i % 6 == 0):
$y = $y + 695 + 65;
$x = 140;
endif;
$i++;
endforeach;
巫下載到被放到廣場上的文件,用正方形將其合併,並會替所有圖像,直到所有方格填滿。但是那個代碼,對於20張圖片來說,最多需要5分鐘!我需要能夠在30秒內運行的東西來填充圖像的方格,然後生成單個文件PDF。
反正有改善嗎?或者還有其他方式可以做得更快更好嗎?
你試過wkhtmltopdf,你會在html中顯示圖像,然後調用wkhtmltopdf – sanj 2013-02-21 10:45:01
我其實不需要那樣做。我將需要在後端處理圖像,因爲我不想在網頁中放置像4800x4800這樣的大文檔。 – roshkattu 2013-02-21 10:47:27