source: extensions/Crop_Image/functions.inc.php @ 22850

Revision 22850, 3.3 KB checked in by Chillexistence, 7 years ago (diff)

Initial Release

Line 
1<?php
2/*
3Plugin Name: Crop Image
4Version: 2.5.c
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 functions.inc.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/functions.php');
15include_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 */
21function 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 */
42function 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        // define default crop frame
72  /*if ($picture['width'] > $conf['original_resize_maxwidth'])
73  {
74    $crop['display_width'] = $conf['original_resize_maxwidth'];
75    $crop['display_height'] = round($picture['height']*$crop['display_width']/$picture['width']);
76   
77    $crop['coi']['x'] = round($crop['coi']['x']*$crop['display_width']/$picture['width']);
78    $crop['coi']['y'] = round($crop['coi']['y']*$crop['display_height']/$picture['height']);
79   
80    $crop['l'] = 0;
81    $crop['r'] = $conf['original_resize_maxwidth'];
82    $crop['t'] = max(0, $crop['coi']['y']-$conf['original_resize_maxheight']/2);
83    $crop['b'] = min($crop['display_height'], $crop['t']+$conf['original_resize_maxheight']);
84  }
85  else
86  {*/
87    $crop['display_width'] = $picture['width'];
88    $crop['display_height'] = $picture['height'];
89   
90    $adapted_crop_height = round($conf['original_resize_maxheight']*$picture['width']/$conf['original_resize_maxwidth']);
91   
92    $crop['l'] = 0;
93    $crop['r'] = $picture['width'];
94    $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2);
95    $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height);
96  //}
97 
98  return $crop;
99}
100
101?>
Note: See TracBrowser for help on using the repository browser.