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

Last change on this file since 13316 was 13316, checked in by plg, 9 years ago

only rotate the biggest size and regenerate smaller sizes

File size: 2.8 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  if ($rotate_hd and get_boolean($image['has_high'])) {
53    $to_rotate_path = file_path_for_type($image['path'], 'high');
54    $quality = $conf['upload_form_hd_quality'];
55    $regenerate_websize = true;
56  }
57  else {
58    $to_rotate_path = $image['path'];
59    $quality = $conf['upload_form_websize_quality'];
60    $regenerate_websize = false;
61  }
62
63  $rotated = new pwg_image($to_rotate_path);
64  $rotated->set_compression_quality($quality);
65  $rotated->rotate($angle);
66  $rotated->write($to_rotate_path);
67
68  if ($regenerate_websize) {
69    ws_images_resizewebsize(
70      array(
71        'image_id' => $params['image_id'],
72        'maxwidth' => $conf['upload_form_websize_maxwidth'],
73        'maxheight' => $conf['upload_form_websize_maxheight'],
74        'quality' => $conf['upload_form_websize_quality'],
75        'automatic_rotation' => $conf['upload_form_automatic_rotation'],
76        'library' => $conf['graphics_library'],
77        ),
78      &$service
79      );
80  }
81
82  ws_images_resizethumbnail(
83    array(
84      'image_id' => $params['image_id'],
85      'maxwidth' => $conf['upload_form_thumb_maxwidth'],
86      'maxheight' => $conf['upload_form_thumb_maxheight'],
87      'quality' => $conf['upload_form_thumb_quality'],
88      'crop' => $conf['upload_form_thumb_crop'],
89      'follow_orientation' => $conf['upload_form_thumb_follow_orientation'],
90      'library' => $conf['graphics_library'],
91      ),
92    &$service
93    );
94
95  $conf['use_exif'] = false;
96  $conf['use_iptc'] = false;
97  update_metadata(array($image['id'] => $image['path']));
98 
99  return true;
100}
101
102?>
Note: See TracBrowser for help on using the repository browser.