Thumbnail Map | Chinese
?
// **************************************** //
Features: Add watermarks to pictures (support Chinese) and generate thumbnails
Parameters: $srcFile picture file name
$dstFile Save picture file name
$markwords Watermark Text Content
$markimage Watermark Picture Address
Save width $dstW Picture
Save Height $dstH Picture
$rate Picture Preservation Quality
// **************************************** //
function Makethumb ($srcFile, $dstFile, $dstW, $dstH, $rate =100, $markwords =null, $markimage =null)
{
$data = getimagesize ($srcFile);
Switch ($data [2])
{
Case 1:
$im = @ImageCreateFromGIF ($srcFile);
Break
Case 2:
$im = @ImageCreateFromJPEG ($srcFile);
Break
Case 3:
$im = @ImageCreateFromPNG ($srcFile);
Break
}
if (! $im) return False;
$srcW =imagesx ($im);
$srcH =imagesy ($im);
$dstX = 0;
$dstY = 0;
if ($srcW * $dstH > $srcH * $dstW)
{
$fdstH = Round ($srcH * $dstW/$srcW);
$dstY = Floor (($dstH-$fdstH)/2);
$fdstW = $dstW;
}
Else
{
$fdstW = Round ($srcW * $dstH/$srcH);
$dstX = Floor (($dstW-$fdstW)/2);
$fdstH = $dstH;
}
$ni =imagecreatetruecolor ($dstW, $dstH);
$dstX = ($dstX <0) 0: $dstX;
$dstY = ($dstX <0) 0: $dstY;
$dstX = ($dstX > ($dstW/2)) Floor ($dstW/2): $dstX;
$dstY = ($dstY > ($dstH/2)) floor ($dstH/s): $dstY;
$white = Imagecolorallocate ($ni, 255,255,255);
$black = Imagecolorallocate ($ni, 0,0,0);
Imagefilledrectangle ($ni, 0,0, $dstW, $dstH, $white);/Fill Background color
Imagecopyresized ($ni, $im, $dstX, $dstY, 0,0, $fdstW, $fdstH, $srcW, $srcH);
//Generate watermarks
if ($markwords!=null)
{
$markwords =iconv ("gb2312", "UTF-8", $markwords);
//Convert text Encoding
Imagettftext ($ni, 9,0,10,15, $white, "Simhei.ttf", $markwords);
//imagettftext (int im,int size,int angle,int x,int y,int col,string fontfile,string text):
//This function will TTF (TrueType Fo NTS) font text is written to the picture.
//parameter: size is a glyph dimension;
///angle is the angle of the font, clockwise, 0 degrees horizontal (from left to right), 90 degrees to the top of the text;
//X,y Two parameter is the coordinate value of the text (the origin is upper left corner);
//col to Word The
//fontfile is the font file name;
//text is the string content.
}
ElseIf ($markimage!=null)
{
$wimage _data = getimagesize ($markimage);
Switch ($wimage _data[2])
{
Case 1:
$wimage = @ImageCreateFromGIF ($markimage);
break;
Case 2:
$wimage = @ImageCreateFromJPEG ($markimage);
break;
Case 3:
$wimage = @ImageCreateFromPNG ($markimage);
break;
}
Imagecopy ($ni, $wimage, 0,0,0,0,88,31);
Imagedestroy ($wimage);
}
Imagejpeg ($ni, $dstFile, $rate);
Imagedestroy ($im);
Imagedestroy ($ni);
End graphics, freeing up memory space
}
?>