On-the-fly image reisizing
- Home
- Core helpers
- Managing files
- On-the-fly image reisizing
If you need a specific image size, then use the File::resizeUrl
method.
First argument is file id or filename.
Second argument is the size definition.
Size definitions
The format is:
{type}{width}x{height}-{position}~{quality}
The type, width, and height parameters are required, but the position and quality parameters (are optional).
Resize types
This is a single letter, either 'r', 'c' or 'm'
r
= resize, up or down, try to fill the area requested
c
= crop, resulting file will always be the width and height requested
m
= resize down only
Width and height
These are in pixels.
Crops require both to be provided, but resizes can accept a 0
for either parameter (but not both) to auto-calculate.
Position
For crops, the anchor position.
First letter is the X crop position, one of l
or c
or r
for left, center, right
Second letter is the Y crop position, one of t
or c
or b
for top, center, bottom.
Quality
This only aplies for jpeg images, and is a number between 0 (worst) and 100 (best)
Resize definition examples
Crop to 500px squarec500x500
Crop to 300 wide by 600 tall, anchoring to the center-bottom of the imagec300x600-cb
Crop to 300 wide by 600 tall, anchoring to the center-top of the image, and saving at quality 70c300x600-ct~70
Resize up or down to fit 750 wide by 250 tallr750x250
Resize down only to fit 500 square, and output at a quality of 50m500x500~50
Performance
Resized images are stored locally in a cache to improve performance.
Note that this means that using a given resize definition in multiple areas will give better performance.