source: extensions/header_manager/include/banner.class.php @ 26298

Revision 26298, 2.2 KB checked in by mistic100, 6 years ago (diff)

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

Line 
1<?php
2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
3
4include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
5
6/**
7 * class derivated from pwg_image, with special function for banner creation
8 */
9class banner_image extends pwg_image
10{
11  function banner_resize($destination_filepath, $selection)
12  {
13    global $conf;
14    $starttime = get_moment();
15
16    // width/height
17    $source_width  = $this->image->get_width();
18    $source_height = $this->image->get_height();
19
20    $crop = array(
21      'width' => $selection['x2']-$selection['x'],
22      'height' => $selection['y2']-$selection['y'],
23      'x' => $selection['x'],
24      'y' => $selection['y'],
25      );
26   
27    // maybe resizing/cropping is useless ?
28    if ($conf['header_manager']['width'] == $source_width and $conf['header_manager']['height'] == $source_height)
29    {
30      // the image doesn't need any resize! We just copy it to the destination
31      copy($this->source_filepath, $destination_filepath);
32      return $this->get_resize_result($destination_filepath, $source_width, $source_height, $starttime);
33    }
34   
35    $this->image->set_compression_quality(90);
36    $this->image->strip();
37   
38    // crop
39    $this->image->crop($crop['width'], $crop['height'], $crop['x'], $crop['y']);
40   
41    // resize to what is displayed on crop screen
42    if ($crop['width'] > $conf['header_manager']['width'])
43    {
44      $this->image->resize($conf['header_manager']['width'], $crop['height']*$conf['header_manager']['width']/$crop['width']);
45    }
46   
47    // save
48    $this->image->write($destination_filepath);
49
50    // everything should be OK if we are here!
51    return $this->get_resize_result($destination_filepath, $crop['width'], $crop['height'], $starttime);
52  }
53 
54  private function get_resize_result($destination_filepath, $width, $height, $time=null)
55  {
56    return array(
57      'source'      => $this->source_filepath,
58      'destination' => $destination_filepath,
59      'width'       => $width,
60      'height'      => $height,
61      'size'        => floor(filesize($destination_filepath) / 1024).' KB',
62      'time'        => $time ? number_format((get_moment() - $time) * 1000, 2, '.', ' ').' ms' : null,
63      'library'     => $this->library,
64    );
65  }
66}
Note: See TracBrowser for help on using the repository browser.