//图片水印
function mark_pic($background, $waterpic, $x, $y){
$back=imagecreatefromjpeg($background);
$water=imagecreatefromgif($waterpic);
$w_w=imagesx($water);
$w_h=imagesy($water);
imagecopy($back, $water, $x, $y, 0, 0, $w_w, $w_h);
imagejpeg($back,"./images/hee8.jpg");
imagedestroy($back);
imagedestroy($water);
}
mark_pic("./images/hee.jpg", "./images/gaolf.gif", 50, 200);
图片旋转
复制代码 代码如下:
$back=imagecreatefromjpeg("./images/hee.jpg");
$new=imagerotate($back, 45, 0);
imagejpeg($new, "./images/hee9.jpg");
图片水平翻转垂直翻转
复制代码 代码如下:
function turn_y($background, $newfile){
$back=imagecreatefromjpeg($background);
$width=imagesx($back);
$height=imagesy($back);
$new=imagecreatetruecolor($width, $height);
for($x=0; $x < $width; $x++){
imagecopy($new, $back, $width-$x-1, 0, $x, 0, 1, $height);
}
imagejpeg($new, $newfile);
imagedestroy($back);
imagedestroy($new);
}
function turn_x($background, $newfile){
$back=imagecreatefromjpeg($background);
$width=imagesx($back);
$height=imagesy($back);
$new=imagecreatetruecolor($width, $height);
for($y=0; $y < $height; $y++){
imagecopy($new, $back,0, $height-$y-1, 0, $y, $width, 1);
}
imagejpeg($new, $newfile);
imagedestroy($back);
imagedestroy($new);
}
turn_y("./images/hee.jpg", "./images/hee11.jpg");
turn_x("./images/hee.jpg", "./images/hee12.jpg");
图片锐化
复制代码 代码如下:
function sharp($background, $degree, $save){
$back=imagecreatefromjpeg($background);
$b_x=imagesx($back);
$b_y=imagesy($back);
$dst=imagecreatefromjpeg($background);
for($i=0; $i<$b_x; $i++){
for($j=0; $j<$b_y; $j++){
$b_clr1=imagecolorsforindex($back, imagecolorat($back, $i-1, $j-1));\\前一个像素颜色数组
$b_clr2=imagecolorsforindex($back, imagecolorat($back, $i, $j));\\取出当前颜色数组
$r=intval($b_clr2["red"]+$degree*($b_clr2["red"]-$b_clr1["red"]));\\加深
$g=intval($b_clr2["green"]+$degree*($b_clr2["green"]-$b_clr1["green"]));
$b=intval($b_clr2["blue"]+$degree*($b_clr2["blue"]-$b_clr1["blue"]));
$r=min(255, max($r, 0));//限制r范围在0-255之间
$g=min(255, max($g, 0));
$b=min(255, max($b, 0));
if(($d_clr=imagecolorexact($dst, $r, $g, $b))==-1){//等于1不在颜色范围内
$d_clr=Imagecolorallocate($dst, $r, $g, $b);//创建一个颜色
}
imagesetpixel($dst, $i, $j, $d_clr);
}
}
imagejpeg($dst, $save);
imagedestroy($back);
imagedestroy($dst);
}
sharp("./images/hee.jpg", 20, "./images/hee13.jpg");
您可能感兴趣的文章: