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

Last change on this file since 12409 was 12409, checked in by Dsls, 13 years ago

First rotateImage commit

File size: 1.5 KB
RevLine 
[12409]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  ),
12  'Rotates a given image'
13);
14
15function ws_image_rotate($params, &$service)
16{
17  if (!is_admin())
18  {
19    return new PwgError(401, 'Access denied');
20  }
21
22  if (empty($params['image_id']))
23  {
24    return new PwgError(403, "image_id or image_path is missing");
25  }
26
27  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
28  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
29  $image_id=(int)$params['image_id'];
30  $angle=(int)$params['angle'];
31  $query='
32SELECT id, path, tn_ext, has_high
33  FROM '.IMAGES_TABLE.'
34  WHERE id = '.$image_id.'
35;';
36  $image = pwg_db_fetch_assoc(pwg_query($query));
37  if ($image == null)
38  {
39    return new PwgError(403, "image_id not found");
40  }
41
42  $image_path = $image['path'];
43
44   
45  $thumb_path = get_thumbnail_path($image);
46
47  $img = new pwg_image($image_path);
48  $img->rotate($angle);
49  $img->write($image_path);
50  update_metadata(array($image_id=>$image_path));
51 
52  foreach (array('thumb','high') as $size) {
53    $resized_path = file_path_for_type($image_path,$size);
54    if (file_exists($resized_path)) {
55      $resized = new pwg_image($resized_path);
56      $resized->rotate($angle);
57      $resized->write($resized_path);
58    }
59  }
60  return true;
61 
62}
63
64?>
Note: See TracBrowser for help on using the repository browser.