Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.01 KB | None | 0 0
  1. diff --git a/class.ImageUpload.php b/class.ImageUpload.php
  2. index d5c785c..a8694db 100644
  3. --- a/class.ImageUpload.php
  4. +++ b/class.ImageUpload.php
  5. @@ -45,6 +45,7 @@ class ImageUpload extends FileUpload {
  6.  
  7.          try {
  8.              $this->_image = new Image($this->_path);
  9. +            $this->_autorotate();
  10.          } catch (ImageException $e) {
  11.              unlink($this->_path);
  12.              $this->_e = new ImageUploadException("Failed to load image: ".$e->getMessage(), self::ERR_PASS, $e);
  13. @@ -54,6 +55,41 @@ class ImageUpload extends FileUpload {
  14.          }
  15.      }
  16.  
  17. +    protected function _autorotate() {
  18. +        switch ($this->_image->getImageOrientation()) {
  19. +            case Imagick::ORIENTATION_TOPLEFT:
  20. +                break;
  21. +            case Imagick::ORIENTATION_TOPRIGHT:
  22. +                $this->_image->flopImage();
  23. +                break;
  24. +            case Imagick::ORIENTATION_BOTTOMRIGHT:
  25. +                $this->_image->rotateImage("#000", 180);
  26. +                break;
  27. +            case Imagick::ORIENTATION_BOTTOMLEFT:
  28. +                $this->_image->flopImage();
  29. +                $this->_image->rotateImage("#000", 180);
  30. +                break;
  31. +            case Imagick::ORIENTATION_LEFTTOP:
  32. +                $this->_image->flopImage();
  33. +                $this->_image->rotateImage("#000", -90);
  34. +                break;
  35. +            case Imagick::ORIENTATION_RIGHTTOP:
  36. +                $this->_image->rotateImage("#000", 90);
  37. +                break;
  38. +            case Imagick::ORIENTATION_RIGHTBOTTOM:
  39. +                $this->_image->flopImage();
  40. +                $this->_image->rotateImage("#000", 90);
  41. +                break;
  42. +            case Imagick::ORIENTATION_LEFTBOTTOM:
  43. +                $this->_image->rotateImage("#000", -90);
  44. +                break;
  45. +            default: // Invalid orientation
  46. +                break;
  47. +        }
  48. +
  49. +        $this->_image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
  50. +    }
  51. +
  52.  }
  53.  
  54.  class ImageUploadException extends Exception {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement