spinball empfiehlt: imagecopymerge
Anstatt die Bilder zu übermalen, füge sie mit Transparenz zusammen. Zuerst den linken Ausschnitt, dann den Rechten. Danach, in einer Schleife, die überlappenden Pixel mit ansteigender / abnehmender Transparenz. Hier ein Beispiel für eine zentrierte Verschmelzung:
PHP
<?php
function fade($left,$right,$overlap = 40) {
// calculate dimensions
list($left_width,$left_height) = getimagesize($left);
list($right_width,$right_height) = getimagesize($right);
$final_width = $left_width + $right_width - $overlap;
$final_height = max($left_height,$right_height);
// create images
$left = imagecreatefrompng($left);
$right = imagecreatefrompng($right);
$final = imagecreatetruecolor($final_width,$final_height);
imagefill($final,0,0,imagecolorallocate($final,255,255,255));
// copy left image
imagecopy($final,$left,0,0,0,0,$left_width - $overlap,$left_height);
// copy right image
imagecopy($final,$right,$left_width,0,$overlap,0,$right_width - $overlap,$right_height);
// produce fader
for($n = 0; $n < $overlap; $n++) {
imagecopymerge($final,$left,$left_width - $overlap + $n,0,$left_width - $overlap + $n,0,1,$left_height,100 - (100 / $overlap) * $n);
imagecopymerge($final,$right,$left_width - $overlap + $n,0,$n,0,1,$right_height,(100 / $overlap) * $n);
}
// output
header("Content-Type: image/png");
imagepng($final,null,0,PNG_NO_FILTERS);
// free resources
imagedestroy($left);
imagedestroy($right);
imagedestroy($final);
}
fade("blue.png","red.png",50);
?>
Alles anzeigen