Ec (2); * & nbsp; function: Functions & quot;, & quot; 100 & quot;); & nbsp; parameters: & nbsp; echo $ BuildFile; & nbsp; script ec (2); script
/*
Function: generate a thumbnail.
MakeBuild ("images/a.jpg", "news/B .jpg", "100 ");
Parameters:
Echo $ BuildFile; original image path
Echo $ newFile; generated thumbnail with Path
Echo $ File_width; thumbnail width value
Echo $ File_height; thumbnail height value (default: width ratio)
Echo $ rate; thumbnail image quality;
*/
Function MakeBuild ($ BuildFile, $ newFile, $ File_width, $ File_height = 0, $ rate = 1000 ){
If (! Is_file ($ BuildFile )){
$ This-> msg ("File". $ BuildFile. "is not a valid graphic file! The system cannot generate a thumbnail of the file! ");
Return false;
}
$ Data = GetImageSize ($ BuildFile );
Switch ($ data [2]) {
Case 1:
$ Im = @ ImageCreateFromGIF ($ BuildFile );
Break;
Case 2:
$ Im = @ ImageCreateFromJPEG ($ BuildFile );
Break;
Case 3:
$ Im = @ ImageCreateFromPNG ($ BuildFile );
Break;
}
If (! $ Im ){
Return false;
}
Else {
$ SrcW = ImageSX ($ im); # obtain the source image width;
$ SrcH = ImageSY ($ im); # obtain the height of the source image;
$ DstX = 0;
$ DstY = 0;
If ($ File_height = 0 ){
$ File_height = $ File_width/$ srcW * $ srcH;
}
If ($ srcW * $ File_height> $ srcH * $ File_width ){
$ FFile_height = round ($ srcH * $ File_width/$ srcW );
$ DstY = floor ($ File_height-$ fFile_height)/2 );
$ FFile_width = $ File_width;
}
Else {
$ FFile_width = round ($ srcW * $ File_height/$ srcH );
$ DstX = floor ($ File_width-$ fFile_width)/2 );
$ FFile_height = $ File_height;
}
$ Ni = ImageCreateTrueColor ($ File_width, $ File_height );
$ DstX = ($ dstX <0 )? 0: $ dstX;
$ DstY = ($ dstX <0 )? 0: $ dstY;
$ DstX = ($ dstX> ($ File_width/2 ))? Floor ($ File_width/2): $ dstX;
$ DstY = ($ dstY> ($ File_height/2 ))? Floor ($ File_height/s): $ dstY;
ImageCopyResized ($ ni, $ im, $ dstX, $ dstY, 0, $ fFile_width, $ fFile_height, $ srcW, $ srcH );
ImageJpeg ($ ni, $ newFile, $ rate); # generate a thumbnail;
Imagedestroy ($ im); # imagedestroy (resource) releases the memory associated with the image
}
}