/*
Functions: Generating thumbnails
Makebuild ("Images/a.jpg", "news/b.jpg", "100");
Parameters:
Echo $BuildFile; Original artwork with path
Echo $newFile; Generated thumbnail band path
echo $File _width; Thumbnail width value
echo $File _height; Thumbnail height value (the default is the proportional value of the width)
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 graphics 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); # get the original width;
$srcH = Imagesy ($im); # get the original height;
$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,0, $fFile _width, $fFile _height, $srcW, $srcH);
Imagejpeg ($ni, $newFile, $rate); # Generate thumbnails;
Imagedestroy ($im); # Imagedestroy (Resource) frees the memory associated with the image
}
}