繁体   English   中英

是否可以使用PHP GD Library用Image滑动特定颜色?

[英]Is it possible to swipe a specific color with an Image using PHP GD Library?

我想知道是否可以使用“图像”划过特定的颜色。

如果我想更改颜色,我将使用它:

$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' >";

但是我想用图像改变背景。

例如,我下载了一个房间的图像,然后画了地面。

http://i.imgur.com/a94EGj9.png

我想知道是否可以移除绿色地面并在其中插入图像,如下所示:

http://i.imgur.com/sXWXkJ5.jpg

有可能这样做吗?

谢谢。

您可能要使用带有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM