开发者

merge Transparent PNG images with other PNG images - PHP

I tried other's solution but it did not worked, so i'm pasting here my code which can copy but can not save it with transparency [the transparent portion gets white] !

<?php
 $dest = imagecreatefrompng('album.png');
 imagealphablending($dest, true);
 imagesavealpha($dest, true);
 $offset = 10;

 $friends = array ('captcha1.png', 'captcha2.png', 'captcha3.png', 'captcha4.png', 'captcha5.png', 'captcha6.png', 'captcha7.png', 'captcha8.png', 'captcha9.png');
 开发者_StackOverflow$baby = array ('baby1.png', 'baby2.png', 'baby3.png', 'baby4.png');

 $ids = getID(0, count($friends)-1, 3);

 for ($i=0;$i<3;$i++)
 {
  $index = $ids[$i];
  $src = imagecreatefrompng($friends[$index]);
  $offsetY = imagesx($src);
  imagecopymerge($dest, $src, 10, $offset, 0, 0, $offsetY, imagesy($src), 100);
  $src = imagecreatefrompng($baby[rand(0,3)]);
  imagealphablending($src, true);
  imagesavealpha($src, true);
  imagecopymerge($dest, $src, ($offsetY + 250), $offset, 0, 0, imagesx($src),imagesy($src), 99);
  $offset = $offset + imagesx($src) + 45;
 }

 header('Content-Type: image/png');
 imagealphablending($dest, true);
 imagesavealpha($dest, true);
 imagepng($dest);

 imagedestroy($dest);
 imagedestroy($src);

 function getID($min, $max, $quantity) {
    $numbers = range($min, $max);
    shuffle($numbers);
    return array_slice($numbers, 0, $quantity);
 }
?>


the solution was to use

imagecopy($dest, $src, ($offsetY + 250), $offset, 0, 0, imagesx($src),imagesy($src));

not

imagecopymerge($dest, $src, ($offsetY + 250), $offset, 0, 0, imagesx($src),imagesy($src), 99);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜