Ignore:
Timestamp:
Dec 28, 2013, 6:08:42 PM (10 years ago)
Author:
mistic100
Message:

update for 2.6 + better calculation + option to force ratio
TODO: issue with PNG (unable to generate thumbnail with IM)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/header_manager/include/banner.class.php

    r15854 r26298  
    11<?php
    2 if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
     2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
    33
    44include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
     
    99class banner_image extends pwg_image
    1010{
    11   function banner_resize($destination_filepath, $x, $y, $x2, $y2, $width, $height)
     11  function banner_resize($destination_filepath, $selection)
    1212  {
    1313    global $conf;
     
    1818    $source_height = $this->image->get_height();
    1919
    20     $resize_dimensions = array(
    21       'width' => $width,
    22       'height'=> $height,
    23       'crop' => array(
    24         'width' => $x2-$x,
    25         'height' => $y2-$y,
    26         'x' => $x,
    27         'y' => $y,
    28         ),
     20    $crop = array(
     21      'width' => $selection['x2']-$selection['x'],
     22      'height' => $selection['y2']-$selection['y'],
     23      'x' => $selection['x'],
     24      'y' => $selection['y'],
    2925      );
    3026   
    31     // maybe resizing/croping is useless ?
    32     if ( $resize_dimensions['crop']['width'] == $source_width and $resize_dimensions['crop']['height'] == $source_height )
     27    // maybe resizing/cropping is useless ?
     28    if ($conf['header_manager']['width'] == $source_width and $conf['header_manager']['height'] == $source_height)
    3329    {
    3430      // the image doesn't need any resize! We just copy it to the destination
    3531      copy($this->source_filepath, $destination_filepath);
    36       return $this->get_resize_result($destination_filepath, $resize_dimensions['width'], $resize_dimensions['height'], $starttime);
     32      return $this->get_resize_result($destination_filepath, $source_width, $source_height, $starttime);
    3733    }
    3834   
     
    4036    $this->image->strip();
    4137   
     38    // crop
     39    $this->image->crop($crop['width'], $crop['height'], $crop['x'], $crop['y']);
     40   
    4241    // resize to what is displayed on crop screen
    43     if ($source_width > $conf['header_manager']['width'])
     42    if ($crop['width'] > $conf['header_manager']['width'])
    4443    {
    45       $this->image->resize($resize_dimensions['width'], $source_height*$resize_dimensions['width']/$source_width);
     44      $this->image->resize($conf['header_manager']['width'], $crop['height']*$conf['header_manager']['width']/$crop['width']);
    4645    }
    47    
    48     // crop
    49     $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']);
    5046   
    5147    // save
     
    5349
    5450    // everything should be OK if we are here!
    55     return $this->get_resize_result($destination_filepath, $resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $starttime);
     51    return $this->get_resize_result($destination_filepath, $crop['width'], $crop['height'], $starttime);
    5652  }
    5753 
     
    6965  }
    7066}
    71 
    72 ?>
Note: See TracChangeset for help on using the changeset viewer.