bool imagefill ( resource image, int x, int y, int color )
imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。
imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。
{
$bg = imagecreatetruecolor($w,$h);
$white = imagecolorallocate($bg,255,255,255);
imagefill($bg,0,0,$white);//填充背景
//获取目标图片信息
$info=getimagesize($src);
$width=$info[0];//目标图片宽度
$height=$info[1];//目标图片高度
switch ($info[2]){
case 1:
$img = imagecreatefromgif($src);
break;
case 2:
$img = imagecreatefromjpeg($src);
break;
case 3:
$img = imagecreatefrompng($src);
break;
default:
exit('不支持的图像格式');
break;
}
if($height < $h)
{
$x=0;
$y=($h-$height)/2;//垂直居中
}
if($width < $w)
{
$x=($w-$width)/2;//水平居中
$y=0;
}
if($height < $h && $width < $w){
$x = ($w-$width)/2;
$y = ($h-$height)/2;
}
imagecopymerge($bg,$img,$x,$y,0,0,$width,$height,100);
imagejpeg($bg,$src,100);
imagedestroy($bg);
imagedestroy($img);
return $src;
}
我代入进去没有任何效果啊
addBg("97972188.jpg",$pieces[0],$pieces[1]);
$o_pic = '97972188.jpg';//图像中要处理的色阶
$begin_r = 178;
$begin_g = 178;
$begin_b = 178;list($src_w,$src_h,$src_type) = getimagesize($o_pic);// 获取原图像信息$file_ext = get_ext($o_pic);//获取扩展名
$target_im = imagecreatetruecolor($src_w,$src_h);//新图
if($file_ext == 'jpg') //转换JPG 开始
{
$src_im = ImageCreateFromJPEG($o_pic);
echo $src_w;
imagecopymerge($target_im,$src_im,0,0,0,0,$src_w,$src_h,100); for($x = 0; $x < $src_w; $x++)
{
for($y = 0; $y < $src_h; $y++)
{
$rgb = imagecolorat($src_im, $x, $y); $r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
//将开始设定的色阶值改为白色
if($r > $begin_r && $g > $begin_g && $b > $begin_b ){
imagecolortransparent($target_im, imagecolorallocate($target_im,$r, $g, $b));
}
}
}}
header("Content: image/jpeg");
imagejpeg($target_im,'c.jpg');
imagedestroy($target_im);