source: extensions/rotateImage/ws_functions.inc.php @ 12417

Revision 12417, 1.8 KB checked in by Dsls, 8 years ago (diff)

rotateImage v0.3 :

  • thumbnails are correctly refreshed
  • strengthened ws
  • small tuning on form display
  • it is now possible to select whether HD should be rotated or not
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5
6$service = &$arr[0];
7$service->addMethod('pwg.image.rotate', 'ws_image_rotate',
8  array(
9  'image_id'=>array(),
10  'angle'=>array('default'=>"90"),
11  'pwg_token' => array(),
12  'rotate_hd' => array('default'=>0)
13  ),
14  'Rotates a given image'
15);
16
17function ws_image_rotate($params, &$service)
18{
19  if (!is_admin())
20  {
21    return new PwgError(401, 'Access denied');
22  }
23
24  if (empty($params['image_id']))
25  {
26    return new PwgError(403, "image_id or image_path is missing");
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
34  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
35  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
36  $image_id=(int)$params['image_id'];
37  $angle=(int)$params['angle'];
38  $rotate_hd = (int) $params['rotate_hd'];
39  $query='
40SELECT id, path, tn_ext, has_high
41  FROM '.IMAGES_TABLE.'
42  WHERE id = '.$image_id.'
43;';
44  $image = pwg_db_fetch_assoc(pwg_query($query));
45  if ($image == null)
46  {
47    return new PwgError(403, "image_id not found");
48  }
49
50  $image_path = $image['path'];
51
52   
53  $thumb_path = get_thumbnail_path($image);
54
55  $img = new pwg_image($image_path);
56  $img->rotate($angle);
57  $img->write($image_path);
58  update_metadata(array($image_id=>$image_path));
59  if ($rotate_hd) {
60    $sizes = array('thumb','high');
61  } else {
62    $sizes = array('thumb');
63  }
64 
65  foreach ($sizes as $size) {
66    $resized_path = file_path_for_type($image_path,$size);
67    if (file_exists($resized_path)) {
68      $resized = new pwg_image($resized_path);
69      $resized->rotate($angle);
70      $resized->write($resized_path);
71    }
72  }
73  return true;
74}
75
76?>
Note: See TracBrowser for help on using the repository browser.