1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Crop Image |
---|
4 | Version: 2.5.d |
---|
5 | Description: Enables to Crop Images already uploaded to the gallery, basic functionality. Tested with v2.5.1, v2.4.6 |
---|
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 functions.inc.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/functions.php'); |
---|
15 | include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); |
---|
16 | |
---|
17 | /** |
---|
18 | * get full size and thumbnail urls and size for a banner |
---|
19 | * @param: string filename |
---|
20 | */ |
---|
21 | function get_file_to_crop($file) |
---|
22 | { |
---|
23 | if (file_exists(get_root_url().$file)) |
---|
24 | { |
---|
25 | return array( |
---|
26 | 'NAME' => $file, |
---|
27 | 'PATH' => get_root_url(). $file, |
---|
28 | 'SIZE' => getimagesize($file), |
---|
29 | ); |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | return false; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * get properties of the jCrop window |
---|
39 | * @param: array picture(width, height[, coi]) |
---|
40 | * @return: array crop(display_width, display_height, l, r, t, b, coi(x, y)) |
---|
41 | */ |
---|
42 | function get_crop_display($picture) |
---|
43 | { |
---|
44 | global $conf; |
---|
45 | |
---|
46 | // find coi |
---|
47 | if (!empty($picture['coi'])) |
---|
48 | { |
---|
49 | $picture['coi'] = array( |
---|
50 | 'l' => char_to_fraction($picture['coi'][0])*$picture['width'], |
---|
51 | 't' => char_to_fraction($picture['coi'][1])*$picture['height'], |
---|
52 | 'r' => char_to_fraction($picture['coi'][2])*$picture['width'], |
---|
53 | 'b' => char_to_fraction($picture['coi'][3])*$picture['height'], |
---|
54 | ); |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | $picture['coi'] = array( |
---|
59 | 'l' => 0, |
---|
60 | 't' => 0, |
---|
61 | 'r' => $picture['width'], |
---|
62 | 'b' => $picture['height'], |
---|
63 | ); |
---|
64 | } |
---|
65 | $crop['coi']['x'] = ($picture['coi']['r']+$picture['coi']['l'])/2; |
---|
66 | $crop['coi']['y'] = ($picture['coi']['b']+$picture['coi']['t'])/2; |
---|
67 | |
---|
68 | $conf['original_resize_maxwidth'] = (isset($conf['original_resize_maxwidth']) and $conf['original_resize_maxwidth'] > 500) ? $conf['original_resize_maxwidth'] : 1000; |
---|
69 | $conf['original_resize_maxheight'] = (isset($conf['original_resize_maxheight']) and $conf['original_resize_maxheight'] > 500) ? $conf['original_resize_maxheight'] : 2000; |
---|
70 | |
---|
71 | $crop['display_width'] = $picture['width']; |
---|
72 | $crop['display_height'] = $picture['height']; |
---|
73 | |
---|
74 | $adapted_crop_height = round($conf['original_resize_maxheight']*$picture['width']/$conf['original_resize_maxwidth']); |
---|
75 | |
---|
76 | $crop['l'] = 0; |
---|
77 | $crop['r'] = $picture['width']; |
---|
78 | $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2); |
---|
79 | $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height); |
---|
80 | |
---|
81 | return $crop; |
---|
82 | } |
---|
83 | |
---|
84 | ?> |
---|