Currently I have 2 image classes. One using the GD Image library and the other which uses Image Magick
The issue i'm having at the moment is that the quality of the GD images after resizing seems to be extremely poor compared to Image Magick.
On the other side Image Magick delays the scripts as it is using an exec().
I don't know if im doing something hideously wrong with my GD class to get such bad quality images:
I'm running the images through at 90 quality.
function create_image($type)
{
switch ($type)
{
case 'thumb':
$maxwidth = constants::IMG_THUMB_WIDTH;
$maxheight = constants::IMG_THUMB_HEIGHT;
break;
case 'normal':
$maxwidth = constants::IMG_NORMAL_WIDTH;
$maxheight = constants::IMG_NORMAL_HEIGHT;
break;
case 'detail':
$maxwidth = constants::IMG_DETAIL_WIDTH;
$maxheight = constants::IMG_DETAIL_HEIGHT;
break;
default:
$maxwidth = constants::IMG_NORMAL_WIDTH;
$maxheight = constants::IMG_NORMAL_HEIGHT;
break;
}
// Get new sizes
list($width, $height) = getimagesize($this->image);
//define the new width and height of the image
$newwidth = $width;
$newheight = $height;
//Set the new width if greater than maxwidth
if (($width >= $maxwidth) || ($height >= $maxheight))
{
if ($width > $height)
{
$newwidth = $maxwidth;
$newheight = $height * ($newwidth/$width);
}
if ($width < $height)
{
$newheight = $maxheight;
$newwidth = $width*($newheight/$height);
}
if ($width == $height)
{
$newwidth = $maxwidth;
$newheight = $maxheight;
}
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($this->image);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Build the file name
$filename = uniqid('img_', 1).'_'.$type.'.jpg';
// Copy the image to the new location
if (imagejpeg($thumb, $this->destination.$filename, constants::IMAGE_QUALITY))
{
//destroy the temp image
imagedestroy($thumb);
return $filename;
}
return 0;
}