Changeset 13843


Ignore:
Timestamp:
Apr 1, 2012, 2:02:36 AM (12 years ago)
Author:
plg
Message:

feature 2604: support rotation on derivatives

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_upload.inc.php

    r13082 r13843  
    270270  }
    271271
     272  // we need to save the rotation angle in the database to compute
     273  // width/height of "multisizes"
     274  $rotation_angle = pwg_image::get_rotation_angle($file_path);
     275  $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
     276 
    272277  $file_infos = pwg_image_infos($file_path);
    273278
     
    281286      'md5sum' => $md5sum,
    282287      'added_by' => $user['id'],
     288      'rotation' => $rotation,
    283289      );
    284290
     
    308314      'md5sum' => $md5sum,
    309315      'added_by' => $user['id'],
     316      'rotation' => $rotation,
    310317      );
    311318
  • trunk/admin/include/image.class.php

    r13736 r13843  
    239239    }
    240240
    241     $rotation = null;
     241    $rotation = 0;
    242242
    243243    $exif = exif_read_data($source_filepath);
     
    261261
    262262    return $rotation;
     263  }
     264
     265  static function get_rotation_code_from_angle($rotation_angle)
     266  {
     267    switch($rotation_angle)
     268    {
     269      case 0:   return 0;
     270      case 90:  return 1;
     271      case 180: return 2;
     272      case 270: return 3;
     273    }
     274  }
     275
     276  static function get_rotation_angle_from_code($rotation_code)
     277  {
     278    switch($rotation_code)
     279    {
     280      case 0: return 0;
     281      case 1: return 90;
     282      case 2: return 180;
     283      case 3: return 270;
     284    }
    263285  }
    264286
     
    424446  {
    425447    $this->image->setInterlaceScheme(Imagick::INTERLACE_LINE);
    426     if ($this->get_width()%2 == 0 && $this->get_height()%2 == 0
    427       && $this->get_width() > 3*$width)
     448   
     449    // TODO need to explain this condition
     450    if ($this->get_width()%2 == 0
     451        && $this->get_height()%2 == 0
     452        && $this->get_width() > 3*$width)
    428453    {
    429454      $this->image->scaleImage($this->get_width()/2, $this->get_height()/2);
    430455    }
     456
    431457    return $this->image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9);
    432458  }
  • trunk/i.php

    r13736 r13843  
    445445  try
    446446  {
    447     $query = 'SELECT coi, width, height FROM '.$prefixeTable.'images WHERE path=\''.$page['src_location'].'\'';
     447    $query = '
     448SELECT
     449    id,
     450    coi,
     451    width,
     452    height,
     453    rotation
     454  FROM '.$prefixeTable.'images
     455  WHERE path=\''.$page['src_location'].'\'
     456;';
     457   
    448458    if ( ($row=pwg_db_fetch_assoc(pwg_query($query))) )
    449459    {
     
    453463      }
    454464      $page['coi'] = $row['coi'];
     465
     466      include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
     467
     468      if (empty($row['rotation']))
     469      {
     470        $page['rotation_angle'] = pwg_image::get_rotation_angle($page['src_path']);
     471       
     472        single_update(
     473          $prefixeTable.'images',
     474          array('rotation' => pwg_image::get_rotation_code_from_angle($page['rotation_angle'])),
     475          array('id' => $row['id'])
     476          );
     477      }
     478      else
     479      {
     480        $page['rotation_angle'] = pwg_image::get_rotation_angle_from_code($row['rotation']);
     481      }
     482
    455483    }
    456484    if (!$row)
     
    472500  ierror("dir create error", 500);
    473501}
    474 
    475 include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
    476502
    477503ignore_user_abort(true);
     
    483509$changes = 0;
    484510
    485 // todo rotate
     511// rotate
     512if (0 != $page['rotation_angle'])
     513{
     514  $image->rotate($page['rotation_angle']);
     515}
    486516
    487517// Crop & scale
     
    555585  $image->strip();
    556586}
     587
    557588$image->set_compression_quality( $params->quality );
    558589$image->write( $page['derivative_path'] );
  • trunk/include/dblayer/functions_mysql.inc.php

    r13038 r13843  
    371371    $separator = $is_first ? '' : ",\n    ";
    372372
    373     if (isset($value) and $value != '')
     373    if (isset($value) and $value !== '')
    374374    {
    375375      $query.= $separator.$key.' = \''.$value.'\'';
  • trunk/include/derivative.inc.php

    r13489 r13843  
    5656    if (!$this->size && isset($infos['width']) && isset($infos['height']))
    5757    {
    58       $this->size = array($infos['width'], $infos['height']);
     58      $width = $infos['width'];
     59      $height = $infos['height'];
     60
     61      // 1 or 5 =>  90 clockwise
     62      // 3 or 7 => 270 clockwise
     63      if ($infos['rotation'] % 2 != 0)
     64      {
     65        $width = $infos['height'];
     66        $height = $infos['width'];
     67      }
     68     
     69      $this->size = array($width, $height);
    5970    }
    6071  }
Note: See TracChangeset for help on using the changeset viewer.