WIP Intermediate sized images for small screen devices #67

This commit is contained in:
Tobias Reich 2014-10-11 00:52:15 +02:00
parent fb35175eca
commit 7387187c5c

View File

@ -44,9 +44,11 @@ class Photo extends Module {
self::dependencies(isset($this->database)); self::dependencies(isset($this->database));
# Check permissions # Check permissions
if (hasPermissions(LYCHEE_UPLOADS_BIG)===false||hasPermissions(LYCHEE_UPLOADS_THUMB)===false) { if (hasPermissions(LYCHEE_UPLOADS_BIG)===false||
Log::error($this->database, __METHOD__, __LINE__, 'Wrong permissions in uploads/'); hasPermissions(LYCHEE_UPLOADS_THUMB)===false||
exit('Error: Wrong permissions in uploads-folder!'); hasPermissions(LYCHEE_UPLOADS_MEDIUM)===false) {
Log::error($this->database, __METHOD__, __LINE__, 'Wrong permissions in uploads/');
exit('Error: Wrong permissions in uploads-folder!');
} }
# Call plugins # Call plugins
@ -169,6 +171,10 @@ class Photo extends Module {
exit('Error: Could not create thumbnail for photo!'); exit('Error: Could not create thumbnail for photo!');
} }
# Create Medium
if ($this->createMedium($path, $photo_name, $info['width'], $info['height'])) $medium = true;
else $medium = false;
# Set thumb url # Set thumb url
$path_thumb = md5($id) . '.jpeg'; $path_thumb = md5($id) . '.jpeg';
@ -235,12 +241,11 @@ class Photo extends Module {
# Call plugins # Call plugins
$this->plugins(__METHOD__, 0, func_get_args()); $this->plugins(__METHOD__, 0, func_get_args());
$info = getimagesize($url);
$photoName = explode(".", $filename); $photoName = explode(".", $filename);
$newUrl = LYCHEE_UPLOADS_THUMB . $photoName[0] . '.jpeg'; $newUrl = LYCHEE_UPLOADS_THUMB . $photoName[0] . '.jpeg';
$newUrl2x = LYCHEE_UPLOADS_THUMB . $photoName[0] . '@2x.jpeg'; $newUrl2x = LYCHEE_UPLOADS_THUMB . $photoName[0] . '@2x.jpeg';
# create thumbnails with Imagick # Create thumbnails with Imagick
if(extension_loaded('imagick')&&$this->settings['imagick']==='1') { if(extension_loaded('imagick')&&$this->settings['imagick']==='1') {
# Read image # Read image
@ -266,6 +271,9 @@ class Photo extends Module {
} else { } else {
# Get size of photo
$info = getimagesize($url);
# Set position and size # Set position and size
$thumb = imagecreatetruecolor($width, $height); $thumb = imagecreatetruecolor($width, $height);
$thumb2x = imagecreatetruecolor($width*2, $height*2); $thumb2x = imagecreatetruecolor($width*2, $height*2);
@ -311,6 +319,48 @@ class Photo extends Module {
} }
private function createMedium($url, $filename, $width, $height, $newWidth = 1920, $newHeight = 1080) {
# Check dependencies
self::dependencies(isset($this->database, $this->settings, $url, $filename, $width, $height));
# Call plugins
$this->plugins(__METHOD__, 0, func_get_args());
# Is photo big enough?
# is Imagick installed?
if (($width>$newWidth||$height>$newHeight)&&
(extension_loaded('imagick')&&$this->settings['imagick']==='1')) {
# $info = getimagesize($url);
$newUrl = LYCHEE_UPLOADS_MEDIUM . $filename;
# Read image
$medium = new Imagick();
$medium->readImage($url);
$medium->scaleImage($newWidth, $newHeight, true);
$medium->writeImage($newUrl);
$medium->clear();
$medium->destroy();
$error = false;
} else {
# Photo too small or
# Imagick not installed
$error = true;
}
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());
if ($error===true) return false;
return true;
}
public function adjustFile($path, $info) { public function adjustFile($path, $info) {
# Check dependencies # Check dependencies