Added GD support for createmedium

This commit is contained in:
pentabion 2017-06-30 16:22:01 +03:00
parent 27f207dcba
commit 908388d97b

View File

@ -230,7 +230,7 @@ final class Photo {
} }
// Create Medium // Create Medium
if ($this->createMedium($path, $photo_name, $info['width'], $info['height'])) $medium = 1; if ($this->createMedium($path, $photo_name, $info['type'], $info['width'], $info['height'])) $medium = 1;
else $medium = 0; else $medium = 0;
// Set thumb url // Set thumb url
@ -386,7 +386,7 @@ final class Photo {
* Photo must be big enough and Imagick must be installed and activated. * Photo must be big enough and Imagick must be installed and activated.
* @return boolean Returns true when successful. * @return boolean Returns true when successful.
*/ */
private function createMedium($url, $filename, $width, $height) { private function createMedium($url, $filename, $type, $width, $height) {
// Excepts the following: // Excepts the following:
// (string) $url = Path to the photo-file // (string) $url = Path to the photo-file
@ -446,12 +446,29 @@ final class Photo {
$medium->destroy(); $medium->destroy();
} else { } else {
$newUrl = LYCHEE_UPLOADS_MEDIUM . $filename;
// Photo too small or // Create image
// Medium is deactivated or $newHeight = $newWidth/($width/$height);
// Imagick not installed $medium = imagecreatetruecolor($newWidth, $newHeight);
$error = true;
// Create new image
switch($type) {
case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break;
case 'image/png': $sourceImg = imagecreatefrompng($url); break;
case 'image/gif': $sourceImg = imagecreatefromgif($url); break;
default: Log::error(Database::get(), __METHOD__, __LINE__, 'Type of photo is not supported');
return false;
break;
}
// Create retina thumb
imagecopyresampled($medium, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($medium, $newUrl, $quality);
imagedestroy($medium);
// Free memory
imagedestroy($sourceImg);
} }
// Call plugins // Call plugins