私は、透過性のある一連のPNGを定期的にループしてそれらをマージする必要があるWebサイトを実行しています。これは長いプロセスになる場合があるため、これを行う最も効率的な方法は何かと考えていました。ImageMagickはそれほど速くないと聞いたので、GDを使用しています..
$firstTime = true; // need to know if it's the first time through the loop
$img = null; // placeholder for each iterative image
$base = null; // will become the final merged image
$width = 0;
$height = 0;
while( $src = getNextImageName() ){
$imageHandle = imagecreatefrompng($src);
imageAlphaBlending($imageHandle, true);
imageSaveAlpha($imageHandle, true);
if( $firstTime ){
$w = imagesx( $img ); // first time in we need to
$h = imagesy( $img ); // save the width & height off
$firstTime = false;
$base = $img; // copy the first image to be the 'base'
} else {
// if it's not the first time, copy the current image on top of base
// and then delete the current image from memory
imagecopy($base, $img, 0, 0, 0, 0, $w, $h);
imagedestroy($img);
}
}
// final cleanup
imagepng($base);
imagedestroy($base);