1 | <?php |
---|
2 | |
---|
3 | if (!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 | |
---|
17 | function 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 | |
---|
40 | $query=' |
---|
41 | SELECT id, path, tn_ext, has_high |
---|
42 | FROM '.IMAGES_TABLE.' |
---|
43 | WHERE id = '.$image_id.' |
---|
44 | ;'; |
---|
45 | $image = pwg_db_fetch_assoc(pwg_query($query)); |
---|
46 | if ($image == null) |
---|
47 | { |
---|
48 | return new PwgError(403, "image_id not found"); |
---|
49 | } |
---|
50 | |
---|
51 | // rotation angle |
---|
52 | if ('auto' == $params['angle']) { |
---|
53 | $angle = $params['angle']; |
---|
54 | } |
---|
55 | else { |
---|
56 | $angle = (int)$params['angle']; |
---|
57 | } |
---|
58 | |
---|
59 | if (get_boolean($params['rotate_hd']) and get_boolean($image['has_high'])) { |
---|
60 | $to_rotate_path = file_path_for_type($image['path'], 'high'); |
---|
61 | $quality = $conf['upload_form_hd_quality']; |
---|
62 | $regenerate_websize = true; |
---|
63 | |
---|
64 | if ('auto' == $angle) { |
---|
65 | $angle = pwg_image::get_rotation_angle($to_rotate_path); |
---|
66 | } |
---|
67 | } |
---|
68 | else { |
---|
69 | $to_rotate_path = $image['path']; |
---|
70 | $quality = $conf['upload_form_websize_quality']; |
---|
71 | $regenerate_websize = false; |
---|
72 | } |
---|
73 | |
---|
74 | $rotated = new pwg_image($to_rotate_path); |
---|
75 | $rotated->set_compression_quality($quality); |
---|
76 | $rotated->rotate($angle); |
---|
77 | $rotated->write($to_rotate_path); |
---|
78 | |
---|
79 | if ($regenerate_websize) { |
---|
80 | ws_images_resizewebsize( |
---|
81 | array( |
---|
82 | 'image_id' => $params['image_id'], |
---|
83 | 'maxwidth' => $conf['upload_form_websize_maxwidth'], |
---|
84 | 'maxheight' => $conf['upload_form_websize_maxheight'], |
---|
85 | 'quality' => $conf['upload_form_websize_quality'], |
---|
86 | 'automatic_rotation' => $conf['upload_form_automatic_rotation'], |
---|
87 | 'library' => $conf['graphics_library'], |
---|
88 | ), |
---|
89 | $service |
---|
90 | ); |
---|
91 | } |
---|
92 | |
---|
93 | ws_images_resizethumbnail( |
---|
94 | array( |
---|
95 | 'image_id' => $params['image_id'], |
---|
96 | 'maxwidth' => $conf['upload_form_thumb_maxwidth'], |
---|
97 | 'maxheight' => $conf['upload_form_thumb_maxheight'], |
---|
98 | 'quality' => $conf['upload_form_thumb_quality'], |
---|
99 | 'crop' => $conf['upload_form_thumb_crop'], |
---|
100 | 'follow_orientation' => $conf['upload_form_thumb_follow_orientation'], |
---|
101 | 'library' => $conf['graphics_library'], |
---|
102 | ), |
---|
103 | $service |
---|
104 | ); |
---|
105 | |
---|
106 | $conf['use_exif'] = false; |
---|
107 | $conf['use_iptc'] = false; |
---|
108 | update_metadata(array($image['id'] => $image['path'])); |
---|
109 | |
---|
110 | return true; |
---|
111 | } |
---|
112 | |
---|
113 | ?> |
---|