Many modules that show images can now be configured to present those images at custom sizes. In all cases, image sizes are configurable through page type parameters. Here are the modules that have been upgraded, with their new parameters for controlling image sizes:
About the parameters
Width and height parameters are always integers, indicating the number of pixels desired for that dimension.
If only width or height are given, images are sized to match that dimension, retaining their aspect ratio, and the crop parameter is ignored.
If both width and height parameters are given, the crop parameter is respected. "fill" (the default value) retains aspect ratio by cropping the image to fill the dimensions given. "fit" retains aspect ratio by sizing the image to fit into a box described by the width and height parameters.
Example: The original image is 640x480,and the module is given in its parameters a width of 100 and height of 100.
- If there is no crop parameter, or the crop parameter is "fill," the module will create a 100x100px image, cropping the left and right sides to make the image fit a 100x100 box without distortion.
- If the crop parameter is set to "fit", the module will resize the entire image (without cropping) so it will fit in a 100x100 box. The resulting image in this case will be 100x75; if the image was 480x640 the resulting image would be 75x100.
New page types
For your convenience, each module that supports image sizing has at least one new core page type that implements image sizing. You can use these out of the box, and can use them as reference when creating your own page types that use image sizing:
Building Image Sizing into Custom Modules
Image sizing is now a core Reason feature, so you can build it into your custom modules. Here is a code snippet that shows how to get the URL of a 100x100 thumbnail:
reason_include_once( 'classes/sized_image.php' );
$rsi = new reasonSizedImage();
// This is not necessary, as "fill" is the default value;
// I am including it to show how to set the crop style.
$url = $rsi->get_url();
You can also pass a reasonSizedImage object to show_image() if you don't want to produce the HTML yourself:
The ReasonSizedImage class was created by Nate White and functionally completed by Frank McQuarry. Colin Macarthur implemented image sizing in the modules and made improvements to ReasonSizedImage, show_image(), and other parts of Reason's image handling code to support these changes.