1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
5 | include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); |
---|
6 | |
---|
7 | /** |
---|
8 | * apply rotation and update the image.rotation column |
---|
9 | */ |
---|
10 | function rotate_image($image_id, $rotate_hd, $angle) |
---|
11 | { |
---|
12 | /* echo '$image_id = '.var_export($image_id, true).'<br>'; */ |
---|
13 | /* echo '$rotate_hd = '.var_export($rotate_hd, true).'<br>'; */ |
---|
14 | /* echo '$angle = '.var_export($angle, true).'<br>'; */ |
---|
15 | global $conf; |
---|
16 | |
---|
17 | $query=' |
---|
18 | SELECT |
---|
19 | id, |
---|
20 | path, |
---|
21 | representative_ext, |
---|
22 | rotation |
---|
23 | FROM '.IMAGES_TABLE.' |
---|
24 | WHERE id = '.$image_id.' |
---|
25 | ;'; |
---|
26 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
27 | if ($row == null) |
---|
28 | { |
---|
29 | return false; |
---|
30 | } |
---|
31 | |
---|
32 | $base_angle = pwg_image::get_rotation_angle_from_code($row['rotation']); |
---|
33 | |
---|
34 | if ($rotate_hd) { |
---|
35 | if ('auto' == $angle) { |
---|
36 | $angle = pwg_image::get_rotation_angle($row['path']); |
---|
37 | $rotation_code = 0; |
---|
38 | } |
---|
39 | else { |
---|
40 | // the angle is based on what the user sees (the thumbnail) and not on |
---|
41 | // the original, which may have a different angle |
---|
42 | $angle = ($base_angle + $angle) % 360; |
---|
43 | |
---|
44 | // the derivatives must not be rotated |
---|
45 | $rotation_code = 4; |
---|
46 | } |
---|
47 | |
---|
48 | if (isset($conf['rotate_image_jpegtran']) and $conf['rotate_image_jpegtran']) { |
---|
49 | $angle = ($angle + 180) % 360; |
---|
50 | $command = 'jpegtran -copy all -rotate '.$angle.' -outfile '.$row['path'].' '.$row['path']; |
---|
51 | exec($command); |
---|
52 | } |
---|
53 | else { |
---|
54 | $image = new pwg_image($row['path']); |
---|
55 | $image->set_compression_quality(98); |
---|
56 | $image->rotate($angle); |
---|
57 | $image->write($row['path']); |
---|
58 | } |
---|
59 | |
---|
60 | $conf['use_exif'] = false; |
---|
61 | $conf['use_iptc'] = false; |
---|
62 | sync_metadata(array($row['id'])); |
---|
63 | |
---|
64 | single_update( |
---|
65 | IMAGES_TABLE, |
---|
66 | array('rotation' => $rotation_code), |
---|
67 | array('id' => $row['id']) |
---|
68 | ); |
---|
69 | } |
---|
70 | elseif ('auto' != $angle) { |
---|
71 | $angle = ($base_angle + $angle) % 360; |
---|
72 | $rotation_code = pwg_image::get_rotation_code_from_angle($angle); |
---|
73 | |
---|
74 | // to show that it's a manual rotation, we use 4,5,6,7 instead of 0,1,2,3 |
---|
75 | $rotation_code+= 4; |
---|
76 | |
---|
77 | single_update( |
---|
78 | IMAGES_TABLE, |
---|
79 | array('rotation' => $rotation_code), |
---|
80 | array('id' => $row['id']) |
---|
81 | ); |
---|
82 | } |
---|
83 | |
---|
84 | delete_element_derivatives($row); |
---|
85 | } |
---|
86 | ?> |
---|