diff --git a/libraries/joomla/image/helper.php b/libraries/joomla/image/helper.php new file mode 100644 index 0000000000000..372826732287b --- /dev/null +++ b/libraries/joomla/image/helper.php @@ -0,0 +1,117 @@ + $info[0], + 'height' => $info[1], + 'type' => $info[2], + 'attributes' => $info[3], + 'bits' => isset($info['bits']) ? $info['bits'] : null, + 'channels' => isset($info['channels']) ? $info['channels'] : null, + 'mime' => $info['mime'], + 'filesize' => filesize($path), + 'orientation' => self::getOrientation((int) $info[0], (int) $info[1]) + ); + + return $properties; + } + + /** + * Compare width and height integers to determine image orientation. + * + * @param integer $width The width value to use for calculation + * @param integer $height The height value to use for calculation + * + * @return mixed Orientation string or null. + * + * @since 3.4 + */ + public static function getOrientation($width, $height) + { + switch (true) + { + case ($width > $height) : + return self::ORIENTATION_LANDSCAPE; + + case ($width < $height) : + return self::ORIENTATION_PORTRAIT; + + case ($width == $height) : + return self::ORIENTATION_SQUARE; + + default : + return null; + } + } +} diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index c48f141861fc6..7d9cbe0cc3185 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -114,49 +114,47 @@ public function __construct($source = null) } /** - * Method to return a properties object for an image given a filesystem path. The - * result object has values for image width, height, type, attributes, mime type, bits, - * and channels. + * Method to return a properties object for an image given a filesystem path. + * The result object has values for image width, height, type, attributes, + * mime type, bits and channels. * * @param string $path The filesystem path to the image for which to get properties. * * @return stdClass * * @since 11.3 + * * @throws InvalidArgumentException * @throws RuntimeException + * + * @deprecated 4.0 Use JImageHelper::getImageFileProperties instead. */ public static function getImageFileProperties($path) { - // Make sure the file exists. - if (!file_exists($path)) - { - throw new InvalidArgumentException('The image file does not exist.'); - } - - // Get the image file information. - $info = getimagesize($path); + return JImageHelper::getImageFileProperties($path); + } - if (!$info) + /** + * Method to detect whether an image's orientation is landscape, portrait or square. + * The orientation will be returned as string. + * + * @access public + * + * @return mixed Orientation string or null. + * + * @since 3.4 + */ + public function getOrientation() + { + if ($this->isLoaded()) { - // @codeCoverageIgnoreStart - throw new RuntimeException('Unable to get properties for the image.'); + $width = $this->getWidth(); + $height = $this->getHeight(); - // @codeCoverageIgnoreEnd + return JImageHelper::getOrientation($width, $height); } - // Build the response object. - $properties = (object) array( - 'width' => $info[0], - 'height' => $info[1], - 'type' => $info[2], - 'attributes' => $info[3], - 'bits' => isset($info['bits']) ? $info['bits'] : null, - 'channels' => isset($info['channels']) ? $info['channels'] : null, - 'mime' => $info['mime'] - ); - - return $properties; + return null; } /**