투명도가있는 PNG 묶음을 반복적으로 루프하여 병합해야하는 웹 사이트를 운영합니다. 때로는 이것이 긴 과정이 될 수 있으므로 가장 효율적인 방법은 무엇인지 궁금 해서요. ImageMagick이 실제로 더 빠르다고 들으면서 저는 GD를 사용하고 있습니다 ..PHP에서 여러 PNG를 가장 효율적으로 병합하는 방법
$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);
프로파일 링을 통해 느린 부분을 확인 했습니까? 다른 기능의 구현은 무엇입니까? – alex
더 효율적으로 또는 더 빠르게 만들고 싶습니까? 여러 이미지가있는 경우 병렬로 병합을 수행 할 수 있습니다. –
ImageMagick 시도 –