Canvas final readonly class
Minn\Media\Canvas · public/minn/src/Minn/Media/Canvas.php · 168 lines
One GD bitmap and the operations the media layer needs on it. Every operation returns a new canvas; alpha is preserved throughout, which is what makes PNG and WebP sub-sizes match the reference's.
Constants and properties
| private | readonly GdImage $image | Promoted from the constructor. |
| prop | readonly int $width | Promoted from the constructor. |
| prop | readonly int $height | Promoted from the constructor. |
Public
| new | __construct(GdImage $image, int $width, int $height)# | ||||
| static | of(GdImage $image): self# | A canvas over a GD image already in hand (what WP_Image_Editor_GD::_save is given). | |||
| method | image(): GdImage# | The GD image behind the canvas (what WP_Image_Editor_GD::_resize hands back). | |||
| static | open(string $path): ?self# | A canvas from an image file, or null when it cannot be decoded or would not fit in memory. The header names the dimensions before a pixel is decoded, so a small file that claims a huge canvas is refused instead of taking the request down. | |||
| method | resample(array $box): self# | Resamples a source box onto a destination box.
| |||
| method | crop(int $x, int $y, int $width, int $height, ?int $targetWidth = NULL, ?int $targetHeight = NULL): self# | A canvas cut to a rectangle, resized to a target when given. | |||
| method | rotate(float $angle): ?self# | A canvas turned by an angle, or null when GD refuses. | |||
| method | flipVertical(): self# | A canvas mirrored on either axis. | |||
| method | flipHorizontal(): self# | A canvas mirrored left to right. | |||
| method | copy(): self# | An untouched copy of the canvas. | |||
| method | write(string $path, string $mime, int $quality): bool# | Writes the bitmap in the given format; the directory is created when missing. | |||
| method | progressive(): self# | The bitmap written progressively from now on (an interlaced JPEG). | |||
| method | baseline(): self# | The bitmap written line by line from now on, as it is by default. | |||
| method | stream(string $mime, int $quality): bool# | Writes the image to the output in a format, at a quality. |
Internals 4
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | affordable(int $width, int $height): bool# | Whether a bitmap of these dimensions fits the memory left to this request: five bytes a pixel for the decoded image (GD keeps four and a little), twice over because every operation makes a second canvas, under what memory_limit leaves after what is already in use. |
| private | memoryLimit(): ?int# | memory_limit in bytes, or null when it is unlimited. |
| private | flipped(int $mode): self# | |
| private | encode(string $mime, ?string $path, int $quality): bool# |
Nothing matches.