source: extensions/Crop_Image/crop.class.php @ 22939

Last change on this file since 22939 was 22939, checked in by Chillexistence, 11 years ago

Adding language

File size: 2.6 KB
Line 
1<?php
2/*
3Plugin Name: Crop Image
4Version: 2.5.d
5Description: Enables to Crop Images already uploaded to the gallery, basic functionality.  Tested with v2.5.1, v2.4.6
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=700
7Author: Chillexistence
8Author URI: http://piwigo.org
9
10Parts of this class.php were taken from Header Manager Extension and adapted.
11*/
12if (!defined('CROPIMAGE_PATH')) die('Hacking attempt!');
13
14include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
15
16/**
17 * class derivated from pwg_image
18 */
19class 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    $this->image->strip();
52   
53    // crop
54    $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']);
55               
56    // save
57    $this->image->write($destination_filepath);
58
59    // everything should be OK if we are here!
60    return $this->get_resize_result($destination_filepath, $resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $starttime);
61  }
62 
63  private function get_resize_result($destination_filepath, $width, $height, $time=null)
64  {
65    return array(
66      'source'      => $this->source_filepath,
67      'destination' => $destination_filepath,
68      'width'       => $width,
69      'height'      => $height,
70      'size'        => floor(filesize($destination_filepath) / 1024).' KB',
71      'time'        => $time ? number_format((get_moment() - $time) * 1000, 2, '.', ' ').' ms' : null,
72      'library'     => $this->library,
73    );
74  }
75}
76
77?>
Note: See TracBrowser for help on using the repository browser.