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

Revision 15854, 2.4 KB checked in by mistic100, 7 years ago (diff)

initial release

Line 
1<?php
2if (!defined('HEADER_MANAGER_PATH')) 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, $x, $y, $x2, $y2, $width, $height)
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    $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        ),
29      );
30   
31    // maybe resizing/croping is useless ?
32    if ( $resize_dimensions['crop']['width'] == $source_width and $resize_dimensions['crop']['height'] == $source_height )
33    {
34      // the image doesn't need any resize! We just copy it to the destination
35      copy($this->source_filepath, $destination_filepath);
36      return $this->get_resize_result($destination_filepath, $resize_dimensions['width'], $resize_dimensions['height'], $starttime);
37    }
38   
39    $this->image->set_compression_quality(90);
40    $this->image->strip();
41   
42    // resize to what is displayed on crop screen
43    if ($source_width > $conf['header_manager']['width'])
44    {
45      $this->image->resize($resize_dimensions['width'], $source_height*$resize_dimensions['width']/$source_width);
46    }
47   
48    // crop
49    $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']);
50   
51    // save
52    $this->image->write($destination_filepath);
53
54    // 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);
56  }
57 
58  private function get_resize_result($destination_filepath, $width, $height, $time=null)
59  {
60    return array(
61      'source'      => $this->source_filepath,
62      'destination' => $destination_filepath,
63      'width'       => $width,
64      'height'      => $height,
65      'size'        => floor(filesize($destination_filepath) / 1024).' KB',
66      'time'        => $time ? number_format((get_moment() - $time) * 1000, 2, '.', ' ').' ms' : null,
67      'library'     => $this->library,
68    );
69  }
70}
71
72?>
Note: See TracBrowser for help on using the repository browser.