public function createThumb(array $specifications, $outputPath)
{
if (!strlen($this->image)) {
return;
}
$sizes = $this->sizes;
$originalImage = $this->loadImage($this->image, $sizes['mime']);
$newWidth = 0;
$newHeight = 0;
if (isset($specifications['width']) && !isset($specifications['height']) && !isset($specifications['maxLength'])) {
$newWidth = $specifications['width'];
$newHeight = $sizes[1] * ($newWidth / $sizes[0]);
} elseif (isset($specifications['height']) && !isset($specifications['width'])) {
$newHeight = $specifications['height'];
$newWidth = $sizes[0] * ($newHeight / $sizes[1]);
} elseif (isset($specifications['height']) && isset($specifications['width'])) {
$newWidth = $specifications['width'];
$newHeight = $specifications['height'];
// $newHeight = (int)(100 * $newWidth / $newHeight);
} elseif (isset($specifications['maxLength'])) {
if ($sizes[0] >= $sizes[1]) {
$newWidth = $specifications['width'];
$newHeight = $sizes[1] * ($newWidth / $sizes[0]);
} else {
$newHeight = $specifications['maxLength'];
$newWidth = $sizes[0] * ($newHeight / $sizes[1]);
}
} else {
$newWidth = $sizes[0];
$newHeight = $sizes[1];
}
$crop_x = 0;
if (isset($specifications['crop_x'])) {
$crop_x = $specifications['crop_x'];
}
$crop_y = 0;
if (isset($specifications['crop_y'])) {
$crop_y = $specifications['crop_y'];
}
$im = @imagecreatetruecolor($newWidth, $newHeight);
imagealphablending($im, false);
imagesavealpha($im, true);
imagecopyresampled($im, $originalImage, 0, 0, $crop_x, $crop_y, $newWidth, $newHeight, $sizes[0], $sizes[1]);
$type = !isset($specifications['mime']) ? $sizes['mime'] : $specifications['mime'];
if ($type == 'image/gif') {
$type = 'image/png';
//to preserve transpacency
// $outputPath = str_replace('.gif', '.png', $outputPath);
}
$this->saveImage($im, $outputPath, $type);
// Free up memory
imagedestroy($im);
imagedestroy($originalImage);
}