Creates a resized image with the aspect ratio maintained.

imageScaleTofit(name, fitWidth, fitHeight [, interpolation] [, blurFactor]) → returns void

Member Function Syntax

someImage.scaleTofit(fitWidth, fitHeight [, interpolation] [, blurFactor])

Argument Reference for the imageScaleTofit function


Required: Yes
The ColdFusion image on which this operation is performed.


Required: Yes
The width of the bounding box in pixels. You can specify an integer, or an empty string ('') if the fitHeight is specified.


Required: Yes
The height of the bounding box in pixels. You can specify an integer, or an empty string ('') if the fitWidth is specified.


Required: No
The interpolation method for resampling. You can specify a specific interpolation algorithm by name (for example, hamming), by image quality (for example, mediumQuality), or by performance (for example, highestPerformance). Values:
  • highestQuality (default)
  • highQuality
  • mediumQuality
  • highestPerformance
  • highPerformance
  • mediumPerformance
  • nearest
  • bilinear
  • bicubic
  • bessel
  • blackman
  • hamming
  • hanning
  • hermite
  • lanczos
  • mitchell
  • quadratic


Required: No
The blur factor used for resampling. The higher the blur factor, the more blurred the image (also, the longer it takes to resize the image). Values:
  • 1-10

Examples sample code invoking the imageScaleTofit function

Tag Syntax

This example shows how to resize an image to fit a 100x100-pixel square while maintaining the aspect ratio.

<!--- Create a ColdFusion image from an existing JPEG file. ---> 
 <cfimage source="../cfdocs/images/artgallery/jeff05.jpg" name="myImage"> 
 <!--- Turn on antialiasing to improve image quality. ---> 
 <cfset imageSetAntialiasing(myImage,"on")> 
 <cfset imageScaleTofit(myImage,100,"","lanczos")> 
 <!--- Display the modified image in a browser. ---> 
 <cfimage source="#myImage#" action="writeToBrowser"> 

Using scaleTofit member function

CF 11+ Scale to fit an image to half its original size (71,71)

imgObj = imageRead("");
cfimage(action="writeToBrowser", source=imgObj);

Fork me on GitHub