|
class pictureReduction{
var $width;
var $height;
// Формирование маленькой картинки без обрезания
function withoutCutting($photo, $new_photo){
$th_width=$this->width;
$th_height=$this->height;
$im = imagecreatefromjpeg($photo);
$width=imageSX($im);
$height=imageSY($im);
if (($width/$height) < ($th_width/$th_height)){
$im1=imagecreatetruecolor($th_width, $th_width*($height/$width));
imagecopyresampled($im1, $im, 0, 0, 0, 0, $th_width, $th_width*($height/$width), $width, $height);
$im2=imagecreatetruecolor($th_width, $th_height);
imagecopy($im2, $im1, 0,0,0,0,$th_width,$th_height);
}
else {
$im1=imagecreatetruecolor(($width*$th_height)/$height, $th_height);
imagecopyresampled($im1, $im, 0, 0, 0, 0, ($width*$th_height)/$height, $th_height, $width, $height);
$im2=imagecreatetruecolor($th_width, $th_height);
imagecopy($im2, $im1, 0,0,0,0,$th_width,$th_height);
}
if (imagejpeg($im2, $new_photo, 100)){
imagedestroy($im);
imagedestroy($im1);
imagedestroy($im2);
return true;
}
else{
imagedestroy($im);
imagedestroy($im1);
imagedestroy($im2);
return false;
}
}
// Формирование маленькой картинки с обрезанием
function withCutting($photo, $new_photo){
$th_width=$this->width;
$th_height=$this->height;
$im = imagecreatefromjpeg($photo);
$width=imageSX($im);
$height=imageSY($im);
if ($width > $height){
$im1=imagecreatetruecolor($th_width, $th_width*($height/$width));
imagecopyresampled($im1, $im, 0, 0, 0, 0, $th_width, $th_width*($height/$width), $width, $height);
}
else {
$im1=imagecreatetruecolor(($width*$th_height)/$height, $th_height);
imagecopyresampled($im1, $im, 0, 0, 0, 0, ($width*$th_height)/$height, $th_height, $width, $height);
}
if (imagejpeg($im1, $new_photo, 100)){
imagedestroy($im);
imagedestroy($im1);
return true;
}
else{
imagedestroy($im);
imagedestroy($im1);
return false;
}
}
}
|
|