Repository navigation
Resizing
📐
Resize modes and the class which resizes an Imagine image.
Enum of resize modes. Backing values match the former Nette\Utils\Image constants, so the bitmask in names of generated thumbnails stays the same.
| Case | Value | Config name | Behaviour |
|---|---|---|---|
FIT |
0 |
fit |
Fits the image into the box, keeping the aspect ratio. |
SHRINK_ONLY |
1 |
shrink_only |
Never enlarges the image. |
STRETCH |
2 |
stretch |
Ignores the aspect ratio. |
FILL |
4 |
fill |
Fills the whole box, keeping the aspect ratio. The overflow is kept. |
EXACT |
8 |
exact |
Fills the whole box, keeping the aspect ratio, and crops the overflow. |
ResizeFlag::fromConfig(string|int|self $value): self creates a flag from shrink_only, ShrinkOnly, a class constant like Image::SHRINK_ONLY or an int. Throws \InvalidArgumentException for an unknown flag.
ResizeFlag::fromConfigList(array $flags): array converts a list of config values to a list of flags.
ResizeFlag::toMask(iterable $flags): int combines flags to a bitmask, used in file names of thumbnails.
Final class with the static method Resizer::resize(ImageInterface $image, ?int $width, ?int $height, array $flags = []): ImageInterface. It resizes the image in place and returns it.
- Without
$widthand$heightthe image is returned unchanged. - With only one of them, the other is calculated from the aspect ratio.
-
STRETCHwith both sizes scales each axis separately. - Otherwise the smaller scale is used (
FIT), or the larger whenFILLorEXACTis set. -
SHRINK_ONLYlimits the scale to1. -
EXACTwith both sizes crops the centre of the result to the box.
use Imagony\ImagineFactory;
use Imagony\Resizing\{ResizeFlag, Resizer};
$image = ImagineFactory::create()->open("photo.jpg");
Resizer::resize($image, 400, 400, [ResizeFlag::EXACT]);