Back to Image class

Method getImageFileProperties

public static \stdClass
getImageFileProperties
(mixed $path)
Method to return a properties object for an image given a filesystem path.
Parameters
  • string $path The filesystem path to the image for which to get properties.
Returns
  • \stdClass
Since
  • 2.5.0
-
  • \InvalidArgumentException
  • \RuntimeException
Class: Image
Project: Joomla

Method getImageFileProperties - Source code

/**
 * 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   2.5.0
 * @throws  \InvalidArgumentException
 * @throws  \RuntimeException
 */
public static function getImageFileProperties($path)
{
    // Make sure the file exists.
    if (!is_file($path)) {
        throw new \InvalidArgumentException('The image file does not exist.');
    }
    // Get the image file information.
    $info = getimagesize($path);
    if (!$info) {
        throw new Exception\UnparsableImageException('Unable to get properties for the image.');
    }
    // Build the response object.
    return (object) ['width' => $info[0], 'height' => $info[1], 'type' => $info[2], 'attributes' => $info[3], 'bits' => $info['bits'] ?? null, 'channels' => $info['channels'] ?? null, 'mime' => $info['mime'], 'filesize' => filesize($path), 'orientation' => self::getOrientationString((int) $info[0], (int) $info[1])];
}