[22939] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Crop Image |
---|
[23127] | 4 | Version: auto |
---|
| 5 | Description: Enables to Crop Images already uploaded to the gallery, basic functionality. Unable to undo the crop once cropped, will have to reload the photo. |
---|
[22939] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=700 |
---|
| 7 | Author: Chillexistence |
---|
| 8 | Author URI: http://piwigo.org |
---|
| 9 | |
---|
| 10 | Parts of this class.php were taken from Header Manager Extension and adapted. |
---|
| 11 | */ |
---|
| 12 | if (!defined('CROPIMAGE_PATH')) die('Hacking attempt!'); |
---|
| 13 | |
---|
| 14 | include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php'); |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * class derivated from pwg_image |
---|
| 18 | */ |
---|
| 19 | class crop_image extends pwg_image |
---|
| 20 | { |
---|
| 21 | function cropimage_resize($destination_filepath, $x, $y, $x2, $y2, $width, $height) |
---|
| 22 | { |
---|
| 23 | global $conf; |
---|
| 24 | $starttime = get_moment(); |
---|
| 25 | |
---|
| 26 | // width/height |
---|
| 27 | $source_width = $this->image->get_width(); |
---|
| 28 | $source_height = $this->image->get_height(); |
---|
| 29 | |
---|
| 30 | $resize_dimensions = array( |
---|
| 31 | 'width' => $width, |
---|
| 32 | 'height'=> $height, |
---|
| 33 | 'crop' => array( |
---|
| 34 | 'width' => $width, |
---|
| 35 | 'height' => $height, |
---|
| 36 | 'x' => $x, |
---|
| 37 | 'y' => $y, |
---|
| 38 | ), |
---|
| 39 | ); |
---|
| 40 | |
---|
| 41 | // maybe resizing/croping is useless ? |
---|
| 42 | if ( $resize_dimensions['crop']['width'] == $source_width and $resize_dimensions['crop']['height'] == $source_height ) |
---|
| 43 | { |
---|
| 44 | // the image doesn't need any resize! We just copy it to the destination |
---|
| 45 | copy($this->source_filepath, $destination_filepath); |
---|
| 46 | return $this->get_resize_result($destination_filepath, $resize_dimensions['width'], $resize_dimensions['height'], $starttime); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | $conf['original_resize_quality'] = isset($conf['original_resize_quality']) ? $conf['original_resize_quality'] : 90; |
---|
| 50 | $this->image->set_compression_quality($conf['original_resize_quality']); |
---|
| 51 | |
---|
| 52 | // crop |
---|
| 53 | $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']); |
---|
| 54 | |
---|
| 55 | // save |
---|
| 56 | $this->image->write($destination_filepath); |
---|
| 57 | |
---|
| 58 | // everything should be OK if we are here! |
---|
| 59 | return $this->get_resize_result($destination_filepath, $resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $starttime); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | private function get_resize_result($destination_filepath, $width, $height, $time=null) |
---|
| 63 | { |
---|
| 64 | return array( |
---|
| 65 | 'source' => $this->source_filepath, |
---|
| 66 | 'destination' => $destination_filepath, |
---|
| 67 | 'width' => $width, |
---|
| 68 | 'height' => $height, |
---|
| 69 | 'size' => floor(filesize($destination_filepath) / 1024).' KB', |
---|
| 70 | 'time' => $time ? number_format((get_moment() - $time) * 1000, 2, '.', ' ').' ms' : null, |
---|
| 71 | 'library' => $this->library, |
---|
| 72 | ); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[22848] | 76 | ?> |
---|