[15854] | 1 | <?php |
---|
[26298] | 2 | defined('HEADER_MANAGER_PATH') or die('Hacking attempt!'); |
---|
[15854] | 3 | |
---|
| 4 | include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php'); |
---|
| 5 | |
---|
| 6 | /** |
---|
| 7 | * class derivated from pwg_image, with special function for banner creation |
---|
| 8 | */ |
---|
| 9 | class banner_image extends pwg_image |
---|
| 10 | { |
---|
[26298] | 11 | function banner_resize($destination_filepath, $selection) |
---|
[15854] | 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 | |
---|
[26298] | 20 | $crop = array( |
---|
| 21 | 'width' => $selection['x2']-$selection['x'], |
---|
| 22 | 'height' => $selection['y2']-$selection['y'], |
---|
| 23 | 'x' => $selection['x'], |
---|
| 24 | 'y' => $selection['y'], |
---|
[15854] | 25 | ); |
---|
| 26 | |
---|
[26298] | 27 | // maybe resizing/cropping is useless ? |
---|
| 28 | if ($conf['header_manager']['width'] == $source_width and $conf['header_manager']['height'] == $source_height) |
---|
[15854] | 29 | { |
---|
| 30 | // the image doesn't need any resize! We just copy it to the destination |
---|
| 31 | copy($this->source_filepath, $destination_filepath); |
---|
[26298] | 32 | return $this->get_resize_result($destination_filepath, $source_width, $source_height, $starttime); |
---|
[15854] | 33 | } |
---|
| 34 | |
---|
| 35 | $this->image->set_compression_quality(90); |
---|
| 36 | $this->image->strip(); |
---|
| 37 | |
---|
[26298] | 38 | // crop |
---|
| 39 | $this->image->crop($crop['width'], $crop['height'], $crop['x'], $crop['y']); |
---|
| 40 | |
---|
[15854] | 41 | // resize to what is displayed on crop screen |
---|
[26298] | 42 | if ($crop['width'] > $conf['header_manager']['width']) |
---|
[15854] | 43 | { |
---|
[26298] | 44 | $this->image->resize($conf['header_manager']['width'], $crop['height']*$conf['header_manager']['width']/$crop['width']); |
---|
[15854] | 45 | } |
---|
| 46 | |
---|
| 47 | // save |
---|
| 48 | $this->image->write($destination_filepath); |
---|
| 49 | |
---|
| 50 | // everything should be OK if we are here! |
---|
[26298] | 51 | return $this->get_resize_result($destination_filepath, $crop['width'], $crop['height'], $starttime); |
---|
[15854] | 52 | } |
---|
| 53 | } |
---|