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

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

Adding language

File size: 2.5 KB
RevLine 
[22853]1<?php
2/*
3Plugin Name: Crop Image
[22939]4Version: 2.5.d
[22853]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    $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?>
Note: See TracBrowser for help on using the repository browser.