Skip to content

Commit

Permalink
Merge pull request #559 from electerious/develop
Browse files Browse the repository at this point in the history
Lychee 3.1.2
  • Loading branch information
electerious authored Jun 12, 2016
2 parents 75b11ac + 8c279a5 commit 475ae57
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 43 deletions.
2 changes: 1 addition & 1 deletion dist/main.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v3.1.2

Released June 12, 2016

- `Improved` Added indexes to SQL fields to improve query execution time (Thanks @qligier, #533)
- `Improved` Protocol-relative URLs for open graph metadata (#546)
- `Improved` Remove metadata from medium-sized images and thumbnails (Imagick only) (#556)
- `Improved` Reduce quality of medium-sized images (Imagick only) (#556)
- `Improved` orientation-handling with Imagick (#556)

## v3.1.1

Released April 30, 2016
Expand All @@ -6,7 +16,7 @@ Released April 30, 2016
- `New` Import of IPTC photo tags (Thanks @qligier, #514)
- `New` Added reset username and password to FAQ (#500 #128)
- `Improved` Removed will-change from the main image to improve the image rendering in Chrome (#501)
- `Improved ` scroll and rendering performance by removing will-change
- `Improved` scroll and rendering performance by removing will-change
- `Improved` Open Facebook and Twitter sharing sheet in new window
- `Improved` EXIF and IPTC extraction (Thanks @qligier, #518)
- `Fixed` broken URL in Update.md (#516)
Expand Down
3 changes: 2 additions & 1 deletion php/Modules/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ final class Database {
'030000', // 3.0.0
'030001', // 3.0.1
'030003', // 3.0.3
'030100' // 3.1.0
'030100', // 3.1.0
'030102' // 3.1.2
);

/**
Expand Down
87 changes: 64 additions & 23 deletions php/Modules/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ public function add(array $files, $albumID = 0, $returnOnError = false) {

}

// Save to DB
$values = array(LYCHEE_TABLE_PHOTOS, $id, $info['title'], $photo_name, $info['description'], $info['tags'], $info['type'], $info['width'], $info['height'], $info['size'], $info['iso'], $info['aperture'], $info['make'], $info['model'], $info['shutter'], $info['focal'], $info['takestamp'], $path_thumb, $albumID, $public, $star, $checksum, $medium);
$query = Database::prepare(Database::get(), "INSERT INTO ? (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum, medium) VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')", $values);
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
Expand Down Expand Up @@ -296,7 +295,7 @@ private function createThumb($url, $filename, $type, $width, $height) {
Plugins::get()->activate(__METHOD__, 0, func_get_args());

// Quality of thumbnails
$thumbQuality = 90;
$quality = 90;

// Size of the thumbnail
$newWidth = 200;
Expand All @@ -312,9 +311,12 @@ private function createThumb($url, $filename, $type, $width, $height) {
// Read image
$thumb = new Imagick();
$thumb->readImage($url);
$thumb->setImageCompressionQuality($thumbQuality);
$thumb->setImageCompressionQuality($quality);
$thumb->setImageFormat('jpeg');

// Remove metadata to save some bytes
$thumb->stripImage();

// Copy image for 2nd thumb version
$thumb2x = clone $thumb;

Expand Down Expand Up @@ -359,12 +361,12 @@ private function createThumb($url, $filename, $type, $width, $height) {

// Create thumb
fastImageCopyResampled($thumb, $sourceImg, 0, 0, $startWidth, $startHeight, $newWidth, $newHeight, $newSize, $newSize);
imagejpeg($thumb, $newUrl, $thumbQuality);
imagejpeg($thumb, $newUrl, $quality);
imagedestroy($thumb);

// Create retina thumb
fastImageCopyResampled($thumb2x, $sourceImg, 0, 0, $startWidth, $startHeight, $newWidth*2, $newHeight*2, $newSize, $newSize);
imagejpeg($thumb2x, $newUrl2x, $thumbQuality);
imagejpeg($thumb2x, $newUrl2x, $quality);
imagedestroy($thumb2x);

// Free memory
Expand Down Expand Up @@ -395,6 +397,9 @@ private function createMedium($url, $filename, $width, $height) {
// Call plugins
Plugins::get()->activate(__METHOD__, 0, func_get_args());

// Quality of medium-photo
$quality = 90;

// Set to true when creation of medium-photo failed
$error = false;

Expand Down Expand Up @@ -427,6 +432,8 @@ private function createMedium($url, $filename, $width, $height) {

// Adjust image
$medium->scaleImage($newWidth, $newHeight, true);
$medium->stripImage();
$medium->setImageCompressionQuality($quality);

// Save image
try { $medium->writeImage($newUrl); }
Expand Down Expand Up @@ -472,20 +479,50 @@ public function adjustFile($path, array $info) {

if (extension_loaded('imagick')&&Settings::get()['imagick']==='1') {

switch ($info['orientation']) {
$image = new Imagick();
$image->readImage($path);

case 3:
$rotateImage = 180;
$orientation = $image->getImageOrientation();

switch ($orientation) {

case Imagick::ORIENTATION_TOPLEFT:
return false;
break;

case 6:
$rotateImage = 90;
$swapSize = true;
case Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
break;

case 8:
$rotateImage = 270;
$swapSize = true;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateImage(new ImagickPixel(), 180);
break;

case Imagick::ORIENTATION_BOTTOMLEFT:
$image->flopImage();
$image->rotateImage(new ImagickPixel(), 180);
break;

case Imagick::ORIENTATION_LEFTTOP:
$image->flopImage();
$image->rotateImage(new ImagickPixel(), -90);
$swapSize = true;
break;

case Imagick::ORIENTATION_RIGHTTOP:
$image->rotateImage(new ImagickPixel(), 90);
$swapSize = true;
break;

case Imagick::ORIENTATION_RIGHTBOTTOM:
$image->flopImage();
$image->rotateImage(new ImagickPixel(), 90);
$swapSize = true;
break;

case Imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage(new ImagickPixel(), -90);
$swapSize = true;
break;

default:
Expand All @@ -494,15 +531,13 @@ public function adjustFile($path, array $info) {

}

if ($rotateImage!==0) {
$image = new Imagick();
$image->readImage($path);
$image->rotateImage(new ImagickPixel(), $rotateImage);
$image->setImageOrientation(1);
$image->writeImage($path);
$image->clear();
$image->destroy();
}
// Adjust photo
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$image->writeImage($path);

// Free memory
$image->clear();
$image->destroy();

} else {

Expand All @@ -512,6 +547,11 @@ public function adjustFile($path, array $info) {

switch ($info['orientation']) {

case 1:
// do nothing
return false;
break;

case 2:
// mirror
// not yet implemented
Expand Down Expand Up @@ -561,6 +601,7 @@ public function adjustFile($path, array $info) {
}

// Recreate photo
// In this step the photos also loses its metadata :(
$newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
imagejpeg($newSourceImg, $path, 100);
Expand Down
4 changes: 2 additions & 2 deletions php/database/albums_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ------------------------------------------------------------

CREATE TABLE IF NOT EXISTS `?` (
`id` bigint(14) NOT NULL,
`id` bigint(14) unsigned NOT NULL,
`title` varchar(100) NOT NULL DEFAULT '',
`description` varchar(1000) DEFAULT '',
`sysstamp` int(11) NOT NULL,
Expand All @@ -11,4 +11,4 @@ CREATE TABLE IF NOT EXISTS `?` (
`downloadable` tinyint(1) NOT NULL DEFAULT '0',
`password` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
4 changes: 2 additions & 2 deletions php/database/log_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ CREATE TABLE IF NOT EXISTS `?` (
`type` varchar(11) NOT NULL,
`function` varchar(100) NOT NULL,
`line` int(11) NOT NULL,
`text` TEXT,
`text` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
16 changes: 9 additions & 7 deletions php/database/photos_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# ------------------------------------------------------------

CREATE TABLE IF NOT EXISTS `?` (
`id` bigint(14) NOT NULL,
`title` varchar(100) NOT NULL,
`id` bigint(14) unsigned NOT NULL,
`title` varchar(100) NOT NULL DEFAULT '',
`description` varchar(1000) DEFAULT '',
`url` varchar(100) NOT NULL,
`tags` varchar(1000) NOT NULL DEFAULT '',
Expand All @@ -20,9 +20,11 @@ CREATE TABLE IF NOT EXISTS `?` (
`focal` varchar(20) NOT NULL,
`takestamp` int(11) DEFAULT NULL,
`star` tinyint(1) NOT NULL,
`thumbUrl` varchar(50) NOT NULL,
`album` varchar(30) NOT NULL DEFAULT '0',
`checksum` VARCHAR(100) DEFAULT NULL,
`thumbUrl` char(37) NOT NULL,
`album` bigint(20) unsigned NOT NULL,
`checksum` char(40) DEFAULT NULL,
`medium` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
PRIMARY KEY (`id`),
KEY `Index_album` (`album`),
KEY `Index_star` (`star`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
2 changes: 1 addition & 1 deletion php/database/settings_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
CREATE TABLE IF NOT EXISTS `?` (
`key` varchar(50) NOT NULL DEFAULT '',
`value` varchar(200) DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
73 changes: 73 additions & 0 deletions php/database/update_030102.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* Update to version 3.1.2
*/

use Lychee\Modules\Database;
use Lychee\Modules\Response;

// Change type of the album id field
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `album` `album` BIGINT(14) UNSIGNED NOT NULL", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not change type of the album id field!');

// Add index to the album id field
$query = Database::prepare($connection, "SHOW INDEX FROM `?` WHERE KEY_NAME = 'Index_album'", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not check if Index_album exists!');

if ($result->num_rows===0) {

$query = Database::prepare($connection, "ALTER TABLE `?` ADD INDEX `Index_album` (`album`)", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not add index to the album id field!');

}

// Add index to the star field
$query = Database::prepare($connection, "SHOW INDEX FROM `?` WHERE KEY_NAME = 'Index_star'", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not check if Index_star exists!');

if ($result->num_rows===0) {

$query = Database::prepare($connection, "ALTER TABLE `?` ADD INDEX `Index_star` (`star`)", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not add index to the star field!');

}

// Change type of the checksum field
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `checksum` `checksum` CHAR(40) NULL DEFAULT NULL", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not change type of the checksum field!');

// Change type of the thumbUrl field
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `thumbUrl` `thumbUrl` CHAR(37) NOT NULL", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not change type of the thumbUrl field!');

// Change type of the id field
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `id` `id` BIGINT(14) UNSIGNED NOT NULL", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not change type of the id field!');

// Change type of the id field
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `id` `id` BIGINT(14) UNSIGNED NOT NULL", array(LYCHEE_TABLE_ALBUMS));
$result = Database::execute($connection, $query, 'update_030102', __LINE__);

if ($result===false) Response::error('Could not change type of the id field!');

// Set version
if (Database::setVersion($connection, '030102')===false) Response::error('Could not update version of database!');

?>
4 changes: 2 additions & 2 deletions php/helpers/getGraphHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function getGraphHeader($photoID) {
else $dir = 'big';

$parseUrl = parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$url = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '?' . $parseUrl['query'];
$picture = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '/../uploads/' . $dir . '/' . $row->url;
$url = '//' . $parseUrl['host'] . $parseUrl['path'] . '?' . $parseUrl['query'];
$picture = '//' . $parseUrl['host'] . $parseUrl['path'] . '/../uploads/' . $dir . '/' . $row->url;

$url = htmlentities($url);
$picture = htmlentities($picture);
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Lychee",
"version": "3.1.1",
"version": "3.1.2",
"description": "Self-hosted photo-management done right.",
"authors": "Tobias Reich <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/lychee.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
lychee = {

title : document.title,
version : '3.1.1',
versionCode : '030101',
version : '3.1.2',
versionCode : '030102',

updatePath : '//update.electerious.com/index.json',
updateURL : 'https://github.com/electerious/Lychee',
Expand Down

0 comments on commit 475ae57

Please sign in to comment.