mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 03:09:58 +03:00
feature 2604: support rotation on derivatives
git-svn-id: http://piwigo.org/svn/trunk@13843 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
3a76852f0c
commit
2ec7183adb
6 changed files with 123 additions and 9 deletions
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
39
i.php
39
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();
|
||||
|
|
|
@ -370,7 +370,7 @@ UPDATE '.$tablename.'
|
|||
{
|
||||
$separator = $is_first ? '' : ",\n ";
|
||||
|
||||
if (isset($value) and $value != '')
|
||||
if (isset($value) and $value !== '')
|
||||
{
|
||||
$query.= $separator.$key.' = \''.$value.'\'';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
39
install/db/120-database.php
Normal file
39
install/db/120-database.php
Normal file
|
@ -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"
|
||||
;
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue