| 1: | <?php |
| 2: | /** |
| 3: | ##DOC-SIGNATURE## |
| 4: | |
| 5: | This file is part of WideImage. |
| 6: | |
| 7: | WideImage is free software; you can redistribute it and/or modify |
| 8: | it under the terms of the GNU Lesser General Public License as published by |
| 9: | the Free Software Foundation; either version 2.1 of the License, or |
| 10: | (at your option) any later version. |
| 11: | |
| 12: | WideImage is distributed in the hope that it will be useful, |
| 13: | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14: | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15: | GNU Lesser General Public License for more details. |
| 16: | |
| 17: | You should have received a copy of the GNU Lesser General Public License |
| 18: | along with WideImage; if not, write to the Free Software |
| 19: | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20: | |
| 21: | * @package Internal/Operations |
| 22: | **/ |
| 23: | |
| 24: | namespace WideImage\Operation; |
| 25: | |
| 26: | use WideImage\TrueColorImage; |
| 27: | |
| 28: | /** |
| 29: | * Rotate operation class |
| 30: | * |
| 31: | * @package Internal/Operations |
| 32: | */ |
| 33: | class Rotate |
| 34: | { |
| 35: | /** |
| 36: | * Returns rotated image |
| 37: | * |
| 38: | * @param \WideImage\Image $image |
| 39: | * @param numeric $angle |
| 40: | * @param int $bgColor |
| 41: | * @param bool $ignoreTransparent |
| 42: | * @return \WideImage\Image |
| 43: | */ |
| 44: | public function execute($image, $angle, $bgColor, $ignoreTransparent) |
| 45: | { |
| 46: | $angle = -floatval($angle); |
| 47: | |
| 48: | if ($angle < 0) { |
| 49: | $angle = 360 + $angle; |
| 50: | } |
| 51: | |
| 52: | $angle = $angle % 360; |
| 53: | |
| 54: | if ($angle == 0) { |
| 55: | return $image->copy(); |
| 56: | } |
| 57: | |
| 58: | $image = $image->asTrueColor(); |
| 59: | |
| 60: | if ($bgColor === null) { |
| 61: | $bgColor = $image->getTransparentColor(); |
| 62: | |
| 63: | if ($bgColor == -1) { |
| 64: | $bgColor = $image->allocateColorAlpha(255, 255, 255, 127); |
| 65: | imagecolortransparent($image->getHandle(), $bgColor); |
| 66: | } |
| 67: | } |
| 68: | |
| 69: | return new TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent)); |
| 70: | } |
| 71: | } |
| 72: |