From f268d97a92f08503759a83ee0ada913c24c892a3 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sat, 7 Dec 2013 15:07:45 +0100 Subject: [PATCH] Added rotate function --- .../lib/system/image/adapter/GDImageAdapter.class.php | 8 ++++++++ .../lib/system/image/adapter/IImageAdapter.class.php | 7 +++++++ .../lib/system/image/adapter/ImageAdapter.class.php | 11 +++++++++++ .../image/adapter/ImagickImageAdapter.class.php | 10 ++++++++++ 4 files changed, 36 insertions(+) diff --git a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php index 47cb79f326..177ab87398 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php @@ -261,6 +261,14 @@ class GDImageAdapter implements IImageAdapter { return $this->image; } + /** + * @see \wcf\system\image\adapter\IImageAdapter::rotate() + */ + public function rotate($degrees) { + // imagerotate interpretes degress as counter-clockwise + return imagerotate($this->image, (360.0 - $degrees), ($this->color ?: 0)); + } + /** * @see \wcf\system\image\adapter\IImageAdapter::isSupported() */ diff --git a/wcfsetup/install/files/lib/system/image/adapter/IImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/IImageAdapter.class.php index 715ca87b45..1f1fef3016 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/IImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/IImageAdapter.class.php @@ -148,6 +148,13 @@ interface IImageAdapter { */ public function getHeight(); + /** + * Rotates an image the specified number of degrees. + * + * @param float $degrees number of degrees to rotate the image clockwise + */ + public function rotate($degrees); + /** * Determines if an image adapter is supported. * diff --git a/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php index 9fd46d94c6..86bc95cf60 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php @@ -174,6 +174,17 @@ class ImageAdapter implements IImageAdapter { return $this->adapter->getHeight(); } + /** + * @see \wcf\system\image\adapter\IImageAdapter::rotate() + */ + public function rotate($degrees) { + if ($degrees > 360.0 || $degrees < 0.0) { + throw new SystemException("Degress must be a value between 0 and 360."); + } + + return $this->adapter->rotate($degrees); + } + /** * @see \wcf\system\image\adapter\IImageAdapter::isSupported() */ diff --git a/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php index 97e55de8be..906cc73c19 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php @@ -192,6 +192,16 @@ class ImagickImageAdapter implements IImageAdapter { return $this->width; } + /** + * @see \wcf\system\image\adapter\IImageAdapter::rotate() + */ + public function rotate($degrees) { + $image = clone $this->imagick; + $image->rotateImage(($this->color ?: new \ImagickPixel()), $degrees); + + return $image; + } + /** * @see \wcf\system\image\adapter\IImageAdapter::isSupported() */ -- 2.20.1