ImageInfo
in package
Lightweight, metadata-only inspection of an image.
Uses only getimagesize() and EXIF parsing; never loads pixels or execs ImageMagick. Mirrors Adapter's fluent API (autorotate/rotate/resize/crop) at the dimension level, so callers can predict the dimensions an Adapter chain would produce and emit correct width/height HTML attributes without actually processing the image.
Table of Contents
Properties
- $extension : string
- $height : int
- $imagepath : string
- $orientation : int
- $rawHeight : int
- $rawWidth : int
- $width : int
Methods
- __construct() : mixed
- autorotate() : $this
- Simulate Adapter::autorotate() at the dimension level.
- boundingBox() : array<string|int, mixed>
- Calculate new size to fit into a bounding box, preserving aspect ratio.
- cleanDimension() : int
- Normalize a dimension value to a pixel count.
- crop() : $this
- Simulate Adapter::crop() at the dimension level.
- getDimensions() : array<string|int, mixed>
- getExtension() : string
- getHeight() : int
- getOrientation() : int
- getRawHeight() : int
- getRawWidth() : int
- getWidth() : int
- readExifOrientation() : int
- Read the EXIF orientation tag of a JPEG file.
- readExifOrientationFromBytes() : int
- Raw-byte fallback for reading the EXIF orientation tag.
- resize() : $this
- Simulate Adapter::resize() at the dimension level.
- rotate() : $this
- Simulate Adapter::rotate() at the dimension level.
Properties
$extension
protected
string
$extension
image format as returned by image_type_to_extension (e.g. 'jpeg', 'png')
$height
protected
int
$height
currently tracked height (reflects chain operations)
$imagepath
protected
string
$imagepath
path to the image
$orientation
protected
int
$orientation
EXIF orientation 1..8; always 1 for non-JPEG
$rawHeight
protected
int
$rawHeight
raw height as stored on disk
$rawWidth
protected
int
$rawWidth
raw width as stored on disk
$width
protected
int
$width
currently tracked width (reflects chain operations)
Methods
__construct()
public
__construct(string $imagepath) : mixed
Parameters
- $imagepath : string
Tags
autorotate()
Simulate Adapter::autorotate() at the dimension level.
public
autorotate() : $this
For JPEGs with EXIF orientation 5/6/7/8 the tracked width and height are swapped; all other cases are no-ops.
Tags
Return values
$thisboundingBox()
Calculate new size to fit into a bounding box, preserving aspect ratio.
public
static boundingBox(int $origW, int $origH, int|string $width, int|string $height) : array<string|int, mixed>
If width and height are given, the result is scaled to fit inside the bounding box. If only one dimension is given, the other is calculated from the aspect ratio.
Parameters
- $origW : int
-
current width
- $origH : int
-
current height
- $width : int|string
-
target width (pixels or %)
- $height : int|string
-
target height (pixels or %)
Tags
Return values
array<string|int, mixed> —[width, height]
cleanDimension()
Normalize a dimension value to a pixel count.
public
static cleanDimension(int|string $dim, int $orig) : int
Accepts an int or a percentage string ("50%"). The percentage is resolved against the given original dimension.
Parameters
- $dim : int|string
- $orig : int
Return values
intcrop()
Simulate Adapter::crop() at the dimension level.
public
crop(int|string $width, int|string $height) : $this
Result equals the output size of Adapter::crop(): exactly ($w, $h) when both are given, or a ($w, $w) / ($h, $h) square when only one is.
Parameters
- $width : int|string
-
in pixels or %
- $height : int|string
-
in pixels or %
Tags
Return values
$thisgetDimensions()
public
getDimensions() : array<string|int, mixed>
Return values
array<string|int, mixed> —[width, height] currently tracked
getExtension()
public
getExtension() : string
Return values
string —'jpeg', 'png', 'gif', 'webp', ...
getHeight()
public
getHeight() : int
Return values
int —currently tracked height (after any chain operations)
getOrientation()
public
getOrientation() : int
Return values
int —EXIF orientation 1..8, defaults to 1 for non-JPEG or missing tag
getRawHeight()
public
getRawHeight() : int
Return values
int —height as stored on disk (stable regardless of chain ops)
getRawWidth()
public
getRawWidth() : int
Return values
int —width as stored on disk (stable regardless of chain ops)
getWidth()
public
getWidth() : int
Return values
int —currently tracked width (after any chain operations)
readExifOrientation()
Read the EXIF orientation tag of a JPEG file.
public
static readExifOrientation(string $path) : int
Prefers exif_read_data() when available; otherwise falls back to a raw-byte scan of the first 70 KB of the file. Returns 1 when no orientation tag is found.
Parameters
- $path : string
Return values
int —1..8
readExifOrientationFromBytes()
Raw-byte fallback for reading the EXIF orientation tag.
public
static readExifOrientationFromBytes(string $path) : int
Exposed so the fallback path can be tested even on systems with the exif extension installed.
Parameters
- $path : string
Tags
Return values
int —1..8
resize()
Simulate Adapter::resize() at the dimension level.
public
resize(int|string $width, int|string $height) : $this
Fits the image into the given bounding box while preserving the aspect ratio. Omitting one dimension (0 or empty) auto-calculates it.
Parameters
- $width : int|string
-
in pixels or %
- $height : int|string
-
in pixels or %
Tags
Return values
$thisrotate()
Simulate Adapter::rotate() at the dimension level.
public
rotate(int $orientation) : $this
Parameters
- $orientation : int
-
EXIF rotation flag 0..8