source: extensions/thumbCropper/ws_functions.inc.php @ 28566

Last change on this file since 28566 was 12501, checked in by Dsls, 12 years ago

Thumb Cropper v0.4 commit

File size: 1.7 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5
6$service = &$arr[0];
7$service->addMethod('pwg.image.thumbcrop', 'ws_thumbcrop',
8  array(
9  'image_id'=>array(),
10  'x1' => array(),
11  'y1' => array(),
12  'x2' => array(),
13  'y2' => array(),
14  'width' => array(),
15  'height' => array(),
16  'pwg_token' => array()
17  ),
18  'Create a thumbnail with advanced options'
19);
20
21function ws_thumbcrop($params, &$service)
22{
23  if (!is_admin())
24  {
25    return new PwgError(401, 'Access denied');
26  }
27
28 
29  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
30  {
31    return new PwgError(403, 'Invalid security token');
32  }
33  foreach (array('x1','y1','x2','y2','width','height','image_id') as $p) {
34          if (!isset($params[$p]))
35          {
36                return new PwgError(403, "$p is missing");
37          }
38  }
39  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
40  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
41  $image_id=(int)$params['image_id'];
42  $x1 = (int) $params['x1'];
43  $x2 = (int) $params['x2'];
44  $y1 = (int) $params['y1'];
45  $y2 = (int) $params['y2'];
46  $width = (int) $params['width'];
47  $height = (int) $params['height'];
48
49  $query='
50SELECT id, path, tn_ext, has_high
51  FROM '.IMAGES_TABLE.'
52  WHERE id = '.$image_id.'
53;';
54  $image = pwg_db_fetch_assoc(pwg_query($query));
55  if ($image == null)
56  {
57    return new PwgError(403, "image_id not found");
58  }
59  $image_path = $image['path'];
60   
61  $thumb_path = get_thumbnail_path($image);
62
63  $img = new pwg_image($image_path);
64 
65  $img->image->crop($x2-$x1,$y2-$y1,$x1,$y1);
66  $img->image->resize($width,$height);
67  $img->write($thumb_path);
68 
69  return true;
70}
71
72?>
Note: See TracBrowser for help on using the repository browser.