开发者

Merge two images with using a sprite

开发者 https://www.devze.com 2023-03-30 08:57 出处:网络
I have an image and an image sprite. I want to merge certain parts of the sprite on top of the image. I have got this working with just one part of the sprite, however when the sprite is merged on top

I have an image and an image sprite. I want to merge certain parts of the sprite on top of the image. I have got this working with just one part of the sprite, however when the sprite is merged on top of the image, the sprite loses its transparency.

$image = $homepath.'/images/orig.png';
$sprite = $homepath.'/images/sprite.png';
$image = imagecreatefromstring(file_get_contents($image));
$sprite = imagecreatefromstring(file_get_contents($sprite));

imagecopymerge($image, $sprite, 50, 50, 80, 0, 80, 100, 100);

imagepng($image, $homepath.'/images/output.png');

Example output: http://i.imgur.com/ZyL9D.png Whatever the dimensions are that I set for the sprite is what has a background color. The co开发者_StackOverflow中文版lor is the same color as the sprite. So in the case, the word "text" are part of the sprite, but if this text was green, the rectangle would be green.

///EDIT///

Figured it out: imagecopyresampled


You probably want another gd function: imagecopyresampled.

0

精彩评论

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

关注公众号