imageScaleTofit

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

name string
Required

The ColdFusion image on which this operation is performed.

fitWidth numeric
Required

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

fitHeight numeric
Required

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

interpolation string

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

blurfactor boolean

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

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"> 

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

imgObj = imageRead("http://cfdocs.org/apple-touch-icon.png");
imgObj.scaleTofit(71,71);
cfimage(action="writeToBrowser", source=imgObj);

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub