PHP图片处理

来源:互联网 发布:老人去世6年无人知 编辑:程序博客网 时间:2024/06/17 20:59
<?php

/*
function thumn($background,$width,$height,$newfile){
list($s_W,$s_h)=getimagesize($background);
if ($width && ($s_w < $s_h)) {
    $width = ($height / $s_h) * $s_w;
} else {
   $height = ($width / $s_w) * $s_h;
}
$new=imagecreatetruecolor($width,$height);
$img=imagecreatefromjpeg($background);


$otsc=imagecolortransparent($img); 
//如何判断这个标识符是否有透明色
if($otsc>=0 && $otsc<imagecolorstotal($img)){
//说明有透明色
//找到透明色
$tran=imagecolorsforindex($img, $otsc);
$newt=imagecolorallocate($new,$tran["red"], $tran["green"], $tran["blue"]);
imagefill($new,0, 0, $newt);
imagecolortransparent($new,$newt);
}
imagecopyresized($new, $img, 0,0,0,0, $width,$height,$s_w, $s_h);
imagejpeg($new,$newfile);
imagedestroy($new);
imagedestroy($img);
}
*/


/*
//图片的裁剪
function cut($background,$cut_x,$cut_y,$cut_width,$cut_height,$newfile){
$back=imagecreatefromjpeg($background);
$new=imagecreatetruecolor($cut_width,$cut_width);
imagecopyresampled($new,$back,0,0,$cut_x,$cut_y,$cut_width, $cut_height, $cut_width, $cut_height);
imagejpeg($new,$newfile);
imagedestroy($back);
imagedestroy($new);
}
*/
/*
//图片加水印(文字水印,图片水印)
function mark_text($background,$text,$x,$y){  //文本水印
$back=imagecreatefromjpeg($background);
$color=imagecolorallocate($back, 0,255, 0);
imagettftext($back, 20, 45, $x, $y, $color, "ygyxsziti2.0.ttf",$text);
imagejpeg($back,"1.jpg");
imagedestroy($back);
}
mark_text("./images/1.jpg","程欢欢",100,100);


function mark_image($background,$picfile,$x,$y){  //图片水印
$back=imagecreatefromjpeg($background);
$water=imagecreatefromjpeg($picfile);


$w_W=imagesx($water);
$w_H=imagesy($water);


imagecopy($back, $water, $x, $y, 0, 0,$w_W, $w_H);
 
imagejpeg($back,$file);
imagedestroy($back);
imagedestroy($water);
}
*/
/*
//图片的旋转 imagerotate
$back=imagecreatefromjpeg("./images/1.jpg");
$new=imagerotate($back,45,0);
imagejpeg($new,"2.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($new);
imagedestroy($back);
}
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($new);
imagedestroy($back);
}
turn_x("./images/1.jpg","3.jpg");
turn_y("./images/1.jpg","4.jpg");
*/


//图片的锐化  imagecolorsforindex()  imagecolorat()
function sharp($background,$gree,$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_col=imagecolorat($back, $i-1, $j-1);
$b_color=imagecolorsforindex($back, $b_col);
$b_col2=imagecolorat($back, $i, $j);
$b_color2=imagecolorsforindex($back, $b_col);


$r=intval($b_color2['red']+$gree*$b_color2['red']-$b_color['red']);
$g=intval($b_color2['green']+$gree*$b_color2['green']-$b_color['green']);
$b=intval($b_color2['blue']+$gree*$b_color2['blue']-$b_color['blue']);


$r=min(255,max($r,0));
$g=min(255,max($g,0));
$b=min(255,max($b,0));
$s=imagecolorexact($dst,$r, $g, $b);
if($s==-1){
$s=imagecolorallocate($dst,$r, $g, $b);
}
imagesetpixel($dst, $i, $j, $s);
}


}
imagejpeg($dst,$save);
imagedestroy($back);
imagedestroy($dst);
}
sharp("./images/1.jpg",1,"5.jpg");



0 0
原创粉丝点击