Image Resizing Methods

For use with image resizing functions like GfxResizeImageBlobWithMethod.

The following properties can be set in the resizing method:

The method cell is always required, other cells may be required depending on the method.

The image cache will not touch images that already have the correct dimensions and rotation unless the noforce parameter is set. This is a route that can be used to take exact control of the quality and to permit the use of animated GIFs - if the end user does the work to properly resize the image, WebHare won't touch it.

Image methods

To illustrate the different methods, the following reference image is used:

 (225x150)

none

The image is left untouched and returned as-is.

fit

If either the width of the image is larger than setwidth or the height is larger than setheight, the image is scaled down proportionally to fit within setwidth and setheight. If only one of setwidth or setheight is given, only the given direction is checked. This only make the image smaller if it's too big.

[ method := "fit", setwidth := 100, setheight := 100 ]
 (100x67)

[ method := "fit", setwidth := 300, setheight := 300 ]
 (225x150)

[ method := "fit", setwidth := 100 ]
 (100x67)

[ method := "fit", setheight := 100 ]
 (150x100)

[ method := "fit", setwidth := 300 ]
 (225x150)

[ method := "fit", setheight := 300 ]
 (225x150)

scale

The same as fit, but if the image is also scaled up proportionally if it's smaller than the given setwidth or setheight. Equivalent to CSS: "background-size: contain;".

[ method := "scale", setwidth := 100, setheight := 100 ]
 (100x67)

[ method := "scale", setwidth := 300, setheight := 300 ]
 (300x200)

[ method := "scale", setwidth := 100 ]
 (100x67)

[ method := "scale", setheight := 100 ]
 (150x100)

[ method := "scale", setwidth := 300 ]
 (300x200)

[ method := "scale", setheight := 300 ]
 (450x300)

fitcanvas, scalecanvas

The same as fit or scale but if both setwidth and setheight are given, the resulting image will always be setwidth by setheight pixels. Any portion of the resulting canvas not covered by the orignal (scaled) image is filled with bgcolor.

[ method := "fitcanvas", setwidth := 100, setheight := 100, bgcolor := "red" ]
 (100x100)

[ method := "fitcanvas", setwidth := 300, setheight := 300, bgcolor := "red" ]
 (300x300)

[ method := "scalecanvas", setwidth := 100, setheight := 100, bgcolor := "red" ]
 (100x100)

[ method := "scalecanvas", setwidth := 300, setheight := 300, bgcolor := "red" ]
 (300x300)

fill

The image is scaled proportionally until it covers the setwidth by setheight area. If only one of setwidth and setheight is given, it behaves like the scale method, otherwise equivalent to CSS: "background-size: cover;".

[ method := "fill", setwidth := 100, setheight := 100 ]
 (100x100)

[ method := "fill", setwidth := 300, setheight := 300 ]
 (300x300)

Legacy resize methods

The old methods 'stretch', 'stretch-x', 'stretch-y', 'crop' and 'cropcanvas' are rarely used nowadays and are error-prone when used. These methods have been deprecated and will not be supported in TypeScript or for WEBP/AVIF outputs

Picking a method: