1 | <?php |
||
2 | class ImageOrientationFixer extends DataExtension { |
||
3 | |||
4 | public function onBeforeWrite() { |
||
5 | $ext = $this->owner->getExtension(); |
||
6 | if (strtolower($ext) == 'jpg' || strtolower($ext) == 'jpeg') { |
||
7 | $path = $this->owner->getFullPath(); |
||
8 | if ($orientation = $this->get_orientation($path)) { |
||
9 | if (extension_loaded('imagick')) { |
||
10 | $this->rotate_imagick($path, $orientation); |
||
11 | } elseif (extension_loaded('gd')) { |
||
12 | $this->rotate_gd($path, $orientation); |
||
13 | } |
||
14 | } |
||
15 | } |
||
16 | |||
17 | parent::onBeforeWrite(); |
||
18 | } |
||
19 | |||
20 | private function get_orientation($path) { |
||
29 | |||
30 | private function rotate_imagick($imagePath, $orientation) { |
||
50 | |||
51 | private function rotate_gd($path, $orientation) { |
||
70 | } |