October CMS ships with an image resizer that lets you change the shape and size of supported images. To resize an image, use the
open method on the
Resizer facade to target a file path.
$image = Resizer::open('path/to/image.jpg');
You may also pass an uploaded file from the page request input.
$image = Resizer::open(Input::file('field_name'));
To resize the image, call the
resize method on the object to perform the resize. The first argument is the image width, the second argument is the image height and the third argument is an array of resize parameters options.
$image->resize(800, 600, ['mode' => 'crop']);
The width and height arguments are also optional, for example, to use the existing width and only adjust the height, pass the second argument as
null. This value is then calculated using original image ratio (automatic proportional scaling) based on the
$image->resize(800, null, [...]);
Finally, use the
save method to save the resized image to a new location.
Note: There is also a
|resizemarkup filter that can be used for resizing images in your themes.
# Resize Parameters
The following elements are supported in the options array are supported:
| ||How the image should be fitted to dimensions|| |
| ||Offset the crop of the resized image|| ||[left, top]|
| ||Quality of the resized image|| |
| ||Amount to sharpen the image|| |
# Available Modes
mode option allows you to specify how the image should be resized. The available modes are as follows:
| ||Automatically choose between |
| ||Resize to the exact dimensions given, without preserving aspect ratio|
| ||Resize to the given height and adapt the width to preserve aspect ratio|
| ||Resize to the given width and adapt the height to preserve aspect ratio|
| ||Crop to the given dimensions after fitting as much of the image as possible inside those|
| ||Fit the image inside the given maximal dimensions, keeping the aspect ratio|