?
Automatic thumbnail $srcfile original file, large image, $photo _small object file, small map, $dstW, $dstH is a small map of the wide, high.
function Makethumb ($srcFile, $photo _small, $dstW, $dstH) {
$data = getimagesize ($srcFile);
Switch ($data [2]) {
Case 1://Picture type, 1 is GIF
$im = @ImageCreateFromGIF ($srcFile);
Break
Case 2://Picture type, 2 is JPG
$im = @imagecreatefromjpeg ($srcFile);
Break
Case 3://Picture type, 3 is PNG chart
$im = @ImageCreateFromPNG ($srcFile);
Break
}
$srcW =imagesx ($im);//The width of the original picture, you can also use $data[0]
$srcH =imagesy ($im);//The height of the original picture, you can also use $data[1]
$srcX the coordinates of the =0;//source graph X,y
$srcY = 0;
if (($srcW/$dstW) > ($srcH/$dstH)) {//Get the width of the picture to be generated
$dstW 2= $dstW;//output picture width, height
$dstH 2= $srcH * $dstW/$srcW;
$dstX =0;//The coordinates of the output graph X,y
$dstY = ($dstH-$dstH 2)/2;
}
else{
$dstH 2= $dstH;//output picture width, height
$dstW 2= $srcW * $dstW/$srcH;
$dstX = ($dstW-$dstW 2)/2;//the coordinates of the output graph X,y
$dstY = 0;
}
$ni =imagecreatetruecolor ($dstW, $dstH);//imagecreate ($dstW, $dstH); draw the size of a blank cloth
$colorBody =imagecolorallocate ($ni, 235,234,233);//define Background color
Imagefill ($ni, 0,0, $colorBody);//Fill background color
Imagecopyresized ($ni, $im, $dstX, $dstY, $srcX, $srcY, $dstW 2, $dstH 2, $srcW, $srcH);
Imagejpeg ($ni, $photo _small);
Imagejpeg ($ni); When the picture is displayed, the annotation is canceled and the picture can be displayed directly on the page.
}
Generate a picture with copyright information
function Makecopyright ($srcFile, $dstFile, $dstW, $dstH) {
$data = getimagesize ($srcFile);
Switch ($data [2]) {
Case 1://Picture type, 1 is GIF
$SRCIMG = @ImageCreateFromGIF ($srcFile);
Break
Case 2://Picture type, 2 is JPG
$SRCIMG = @imagecreatefromjpeg ($srcFile);
Break
Case 3://Picture type, 3 is PNG chart
$SRCIMG = @ImageCreateFromPNG ($srcFile);
Break
}
$srcW =imagesx ($SRCIMG);//The width of the original picture, you can also use $data[0]
$srcH =imagesy ($SRCIMG);//The height of the original picture, you can also use $data[1]
if (($srcW/$dstW) > ($srcH/$dstH)) {//Get the width of the picture to be generated
$dstW 2= $dstW;//output picture width, height
$dstH 2= $srcH * $dstW/$srcW;
}
else{
$dstH 2= $dstH;//output picture width, height
$dstW 2= $srcW * $dstW/$srcH;
}
$dstimg =imagecreatetruecolor ($dstW 2, $dstH 2);//Draw the size of a blank cloth
Imagecopyresized ($dstimg, $SRCIMG, 0,0,0,0, $dstW 2, $dstH 2, $srcW, $srcH);
Define the text to write
$word = "http://www.webjx.com";//Text
$font =5;//Font
$wordColor =imagecolorallocate ($dstimg, 0x08,0x00,0x00);//Color
$wordX = $dstW 2-200;//x coordinates
$wordY = $dstH 2-20;//y coordinates
Imagestring ($dstimg, $font, $wordX, $wordY, $word, $wordColor);/write text
Imagejpeg ($dstimg, $dstFile);
Imagejpeg ($ni); When the picture is displayed, the annotation is canceled and the picture can be displayed directly on the page.
}
Call
$srcFile = $pimg _name;//Gets the file name extension:
$type =substr (STRRCHR ($pimg _name, "."), 1);
$photo _id=date ("Ymdhis");
$DST _small= $photo _id. " _s. ". $type; Small figure
$DST _big= $photo _id. " _b. ". $type; Big picture
Makethumb ($pimg, ". /cpzs/". $dst _small,120,90);//120,90 for small plot width, high
Makecopyright ($pimg, ". /cpzs/". $dst _big,600,480);
if (Copy ($pimg, ".. /cpzs/". $dst _big))
echo "File upload success <br>";
Else
echo "File upload failed <br>";
?>