aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/include/functions_upload.inc.php7
-rw-r--r--admin/include/image.class.php32
-rw-r--r--i.php39
-rw-r--r--include/dblayer/functions_mysql.inc.php2
-rw-r--r--include/derivative.inc.php13
-rw-r--r--install/db/120-database.php39
6 files changed, 123 insertions, 9 deletions
diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php
index 2a5206c1b..19482ee02 100644
--- a/admin/include/functions_upload.inc.php
+++ b/admin/include/functions_upload.inc.php
@@ -269,6 +269,11 @@ SELECT
}
}
+ // we need to save the rotation angle in the database to compute
+ // width/height of "multisizes"
+ $rotation_angle = pwg_image::get_rotation_angle($file_path);
+ $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
+
$file_infos = pwg_image_infos($file_path);
if (isset($image_id))
@@ -280,6 +285,7 @@ SELECT
'height' => $file_infos['height'],
'md5sum' => $md5sum,
'added_by' => $user['id'],
+ 'rotation' => $rotation,
);
if (isset($level))
@@ -307,6 +313,7 @@ SELECT
'height' => $file_infos['height'],
'md5sum' => $md5sum,
'added_by' => $user['id'],
+ 'rotation' => $rotation,
);
if (isset($level))
diff --git a/admin/include/image.class.php b/admin/include/image.class.php
index 30e62de1d..61b1ab277 100644
--- a/admin/include/image.class.php
+++ b/admin/include/image.class.php
@@ -238,7 +238,7 @@ class pwg_image
return null;
}
- $rotation = null;
+ $rotation = 0;
$exif = exif_read_data($source_filepath);
@@ -262,6 +262,28 @@ class pwg_image
return $rotation;
}
+ static function get_rotation_code_from_angle($rotation_angle)
+ {
+ switch($rotation_angle)
+ {
+ case 0: return 0;
+ case 90: return 1;
+ case 180: return 2;
+ case 270: return 3;
+ }
+ }
+
+ static function get_rotation_angle_from_code($rotation_code)
+ {
+ switch($rotation_code)
+ {
+ case 0: return 0;
+ case 1: return 90;
+ case 2: return 180;
+ case 3: return 270;
+ }
+ }
+
/** Returns a normalized convolution kernel for sharpening*/
static function get_sharpen_matrix($amount)
{
@@ -423,11 +445,15 @@ class image_imagick implements imageInterface
function resize($width, $height)
{
$this->image->setInterlaceScheme(Imagick::INTERLACE_LINE);
- if ($this->get_width()%2 == 0 && $this->get_height()%2 == 0
- && $this->get_width() > 3*$width)
+
+ // TODO need to explain this condition
+ if ($this->get_width()%2 == 0
+ && $this->get_height()%2 == 0
+ && $this->get_width() > 3*$width)
{
$this->image->scaleImage($this->get_width()/2, $this->get_height()/2);
}
+
return $this->image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9);
}
diff --git a/i.php b/i.php
index f59bf2aa9..5ecf831a0 100644
--- a/i.php
+++ b/i.php
@@ -444,7 +444,17 @@ if (strpos($page['src_location'], '/pwg_representative/')===false
{
try
{
- $query = 'SELECT coi, width, height FROM '.$prefixeTable.'images WHERE path=\''.$page['src_location'].'\'';
+ $query = '
+SELECT
+ id,
+ coi,
+ width,
+ height,
+ rotation
+ FROM '.$prefixeTable.'images
+ WHERE path=\''.$page['src_location'].'\'
+;';
+
if ( ($row=pwg_db_fetch_assoc(pwg_query($query))) )
{
if (isset($row['width']))
@@ -452,6 +462,24 @@ if (strpos($page['src_location'], '/pwg_representative/')===false
$page['original_size'] = array($row['width'],$row['height']);
}
$page['coi'] = $row['coi'];
+
+ include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
+
+ if (empty($row['rotation']))
+ {
+ $page['rotation_angle'] = pwg_image::get_rotation_angle($page['src_path']);
+
+ single_update(
+ $prefixeTable.'images',
+ array('rotation' => pwg_image::get_rotation_code_from_angle($page['rotation_angle'])),
+ array('id' => $row['id'])
+ );
+ }
+ else
+ {
+ $page['rotation_angle'] = pwg_image::get_rotation_angle_from_code($row['rotation']);
+ }
+
}
if (!$row)
{
@@ -472,8 +500,6 @@ if (!mkgetdir(dirname($page['derivative_path'])))
ierror("dir create error", 500);
}
-include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
-
ignore_user_abort(true);
set_time_limit(0);
@@ -482,7 +508,11 @@ $timing['load'] = time_step($step);
$changes = 0;
-// todo rotate
+// rotate
+if (0 != $page['rotation_angle'])
+{
+ $image->rotate($page['rotation_angle']);
+}
// Crop & scale
$o_size = $d_size = array($image->get_width(),$image->get_height());
@@ -554,6 +584,7 @@ if ($d_size[0]*$d_size[1] < 256000)
{// strip metadata for small images
$image->strip();
}
+
$image->set_compression_quality( $params->quality );
$image->write( $page['derivative_path'] );
$image->destroy();
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
index 65cb9fbd2..a7655e544 100644
--- a/include/dblayer/functions_mysql.inc.php
+++ b/include/dblayer/functions_mysql.inc.php
@@ -370,7 +370,7 @@ UPDATE '.$tablename.'
{
$separator = $is_first ? '' : ",\n ";
- if (isset($value) and $value != '')
+ if (isset($value) and $value !== '')
{
$query.= $separator.$key.' = \''.$value.'\'';
}
diff --git a/include/derivative.inc.php b/include/derivative.inc.php
index 144e76a27..ca840a4d9 100644
--- a/include/derivative.inc.php
+++ b/include/derivative.inc.php
@@ -55,7 +55,18 @@ final class SrcImage
if (!$this->size && isset($infos['width']) && isset($infos['height']))
{
- $this->size = array($infos['width'], $infos['height']);
+ $width = $infos['width'];
+ $height = $infos['height'];
+
+ // 1 or 5 => 90 clockwise
+ // 3 or 7 => 270 clockwise
+ if ($infos['rotation'] % 2 != 0)
+ {
+ $width = $infos['height'];
+ $height = $infos['width'];
+ }
+
+ $this->size = array($width, $height);
}
}
diff --git a/install/db/120-database.php b/install/db/120-database.php
new file mode 100644
index 000000000..ec156e0df
--- /dev/null
+++ b/install/db/120-database.php
@@ -0,0 +1,39 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+ die('Hacking attempt!');
+}
+
+$upgrade_description = 'rotation mode (code, not angle) is stored in the database';
+
+$query = 'ALTER TABLE '.IMAGES_TABLE.' ADD COLUMN rotation tinyint DEFAULT NULL';
+pwg_query($query);
+
+echo
+"\n"
+. $upgrade_description
+."\n"
+;
+?> \ No newline at end of file