Please Log in to join the conversation.
function resizeImageGD2($src_file, $dest_file, $destWidth,$destHeight){
$imginfo = getimagesize($src_file);
if ($imginfo == null) {
$this->raiseError("Error: Unable to execute getimagesize function");
return false;
}
$width=$imginfo[0];
$height=$imginfo[1];
$thumb_size=100;
if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
// GD can only handle JPG & PNG images
if ($imginfo[2] != 2 && $imginfo[2] != 3 && ($imginfo[2] == 1 && !function_exists(imagecreatefromgif))){
$this->raiseError("Error: GD2 Unable to create image from imagetype function");
return false;
}
if ($imginfo[2] == 2)
$src_img = imagecreatefromjpeg($src_file);
elseif ($imginfo[2] == 1)
$src_img = imagecreatefromgif($src_file);
else
$src_img = imagecreatefrompng($src_file);
if (!$src_img) {
$this->raiseError("Error: GD2 Unable to create image from imagetype function");
return false;
}
$dst_img = imagecreatetruecolor($thumb_size, $thumb_size);
imagecopyresampled($dst_img, $src_img, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height);
if ($imginfo[2] == 2) {
imagejpeg($dst_img, $dest_file, $this->_JPEGquality);
} elseif ($imginfo[2] == 1) {
if(function_exists('imagegif')) {
imagegif($dst_img, $dest_file);
} else {
$this->raiseError("Error: GIF Uploads are not supported by this version of GD");
return false;
}
} else {
imagepng($dst_img, $dest_file);
}
imagedestroy($src_img);
imagedestroy($dst_img);
return true;
}
The function below will take an image and regardless of whether its a portrait or landscape size image it will generate a square thumbnail that is not distorted
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.