diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index 4e469dd663427..ec4f97d7a84b4 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -844,6 +844,58 @@ public function rotate($angle, $background = -1, $createNew = true) } } + /** + * Method to flip the current image. + * + * @param integer $mode The flip mode for flipping the image + * @param boolean $createNew If true the current image will be cloned, flipped and returned; else + * the current image will be flipped and returned. + * + * @return JImage + * + * @since 11.3 + * @throws LogicException + */ + public function flip($mode, $createNew = true) + { + // Make sure the resource handle is valid. + if (!$this->isLoaded()) + { + throw new LogicException('No valid image was loaded.'); + } + + // Create the new truecolor image handle. + $handle = imagecreatetruecolor($this->getWidth(), $this->getHeight()); + + // Copy the image + imagecopy($handle, $this->handle, 0, 0, 0, 0, $this->getWidth(), $this->getHeight()); + + // Flip the image + if (!imageflip($handle, $mode)) + { + throw new LogicException('Unable to flip the image.'); + } + + // If we are resizing to a new image, create a new JImage object. + if ($createNew) + { + // @codeCoverageIgnoreStart + $new = new JImage($handle); + + return $new; + + // @codeCoverageIgnoreEnd + } + + // Free the memory from the current handle + $this->destroy(); + + // Swap out the current handle for the new image handle. + $this->handle = $handle; + + return $this; + } + /** * Method to write the current image out to a file. *