Created
February 26, 2016 20:05
-
-
Save christianromney/dfdf61538edb5b01c71b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class FakeImage { | |
| function rotate($deg) { | |
| echo "Rotating $deg degrees\n"; | |
| return $this; | |
| } | |
| function mirror(){ | |
| echo "Mirroring\n"; | |
| return $this; | |
| } | |
| function copy() { | |
| echo "Copying\n"; | |
| return $this; | |
| } | |
| function saveToFile($path) { | |
| echo "Saving image to $path\n"; | |
| return $this; | |
| } | |
| } | |
| class WideImage_Operation_ExifOrient | |
| { | |
| // orientation constants | |
| const MIRROR = 2; | |
| const ROTATE_180 = 3; | |
| const ROTATE_180_MIRROR = 4; | |
| const ROTATE_90_MIRROR = 5; | |
| const ROTATE_90 = 6; | |
| const ROTATE_270_MIRROR = 7; | |
| const ROTATE_270 = 8; | |
| function execute($image, $orientation) | |
| { | |
| if (!isset($image)) throw new Exception('No image given'); | |
| if (!isset($orientation)) throw new Exception('No orientation given'); | |
| switch ($orientation) { | |
| case self::MIRROR: | |
| return $image->mirror(); | |
| case self::ROTATE_180: | |
| return $image->rotate(180); | |
| case self::ROTATE_180_MIRROR: | |
| return $image->rotate(180)->mirror(); | |
| case self::ROTATE_90_MIRROR: | |
| return $image->rotate(90)->mirror(); | |
| case self::ROTATE_90: | |
| return $image->rotate(90); | |
| case self::ROTATE_270_MIRROR: | |
| return $image->rotate(-90)->mirror(); | |
| case self::ROTATE_270: | |
| return $image->rotate(-90); | |
| default: | |
| return $image->copy(); | |
| } | |
| } | |
| } | |
| // fake data for testing | |
| $exif = array('Orientation' => 7); | |
| $image = new FakeImage(); | |
| $imageWithText = "/tmp/image.jpg"; | |
| // use the class | |
| $transformation = new WideImage_Operation_ExifOrient(); | |
| $transformation->execute($image, $exif['Orientation']); | |
| $image->saveToFile($imageWithText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment