[英]Is it possible to swipe a specific color with an Image using PHP GD Library?
I would like to know if is it possible to swipe a specific color with an Image. 我想知道是否可以使用“图像”划过特定的颜色。
I would use this if I wanted to change the color: 如果我想更改颜色,我将使用它:
$imgname = "http://i.imgur.com/a94EGj9.png";
$im = imagecreatefrompng ($imgname);
imagetruecolortopalette($im,false, 255);
$index = imagecolorclosest ( $im, 21,194,37 ); // get color
imagecolorset($im,$index,255,255,255); // SET NEW COLOR
$time = time();
$imgname = "img".$time.".png";
imagegif($im, $imgname );
imagedestroy($im);
echo "<img src='".$imgname."' width='500' height='500' >";
But I want to change the background with an image. 但是我想用图像改变背景。
Example, I downloaded a image of a room, and I painted the ground. 例如,我下载了一个房间的图像,然后画了地面。
http://i.imgur.com/a94EGj9.png http://i.imgur.com/a94EGj9.png
I would like to know if I can remove the green ground and insert an image in there, like this: 我想知道是否可以移除绿色地面并在其中插入图像,如下所示:
http://i.imgur.com/sXWXkJ5.jpg http://i.imgur.com/sXWXkJ5.jpg
Is it possible to do that? 有可能这样做吗?
Thank you. 谢谢。
You probably want to use imagecopymerge, with 100 alpha. 您可能要使用带有100 alpha的imagecopymerge。
$background_layer = imagecreatefrompng('image_background.png');
$imgname = "http://i.imgur.com/a94EGj9.png";
$im = imagecreatefrompng ($imgname);
$color = imagecolorallocate($im, 21, 194, 37);
imagecolortransparent($im, $color);
imagecopymerge($background_layer, $im, 0, 0, 0, 0, imagesx($im), imagesy($im), 100);
header("Content-Type: image/png");
imagepng($background_layer);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.