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 @@ + \ No newline at end of file