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

Last change on this file since 13315 was 13315, checked in by plg, 12 years ago

use JPEG compression quality settings for rotate photo

File size: 2.1 KB
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  global $conf;
20 
21  if (!is_admin())
22  {
23    return new PwgError(401, 'Access denied');
24  }
25
26  if (empty($params['image_id']))
27  {
28    return new PwgError(403, "image_id or image_path is missing");
29  }
30
31  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
32  {
33    return new PwgError(403, 'Invalid security token');
34  }
35
36  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
37  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
38  $image_id=(int)$params['image_id'];
39  $angle=(int)$params['angle'];
40  $rotate_hd = get_boolean($params['rotate_hd']);
41  $query='
42SELECT id, path, tn_ext, has_high
43  FROM '.IMAGES_TABLE.'
44  WHERE id = '.$image_id.'
45;';
46  $image = pwg_db_fetch_assoc(pwg_query($query));
47  if ($image == null)
48  {
49    return new PwgError(403, "image_id not found");
50  }
51
52  $image_path = $image['path'];
53
54   
55  $thumb_path = get_thumbnail_path($image);
56
57  $img = new pwg_image($image_path);
58  $img->set_compression_quality($conf['upload_form_websize_quality']);
59  $img->rotate($angle);
60  $img->write($image_path);
61  update_metadata(array($image_id=>$image_path));
62  if ($rotate_hd) {
63    $sizes = array('thumb','high');
64  } else {
65    $sizes = array('thumb');
66  }
67 
68  foreach ($sizes as $size) {
69    $resized_path = file_path_for_type($image_path,$size);
70   
71    $quality = $conf['upload_form_hd_quality'];
72    if ('thumb' == $size) {
73      $quality = $conf['upload_form_thumb_quality'];
74    }
75   
76    if (file_exists($resized_path)) {
77      $resized = new pwg_image($resized_path);
78      $resized->set_compression_quality($quality);
79      $resized->rotate($angle);
80      $resized->write($resized_path);
81    }
82  }
83  return true;
84}
85
86?>
Note: See TracBrowser for help on using the repository browser.