ImageCFC: Documentation: Method Description

imageCFC.scaleWidth()

Description

Resizes an image to a specific width, calculating the height to maintain the image's aspect ratio.

This method simply calls the resize() method.

Returns

A structure containing the following fields:

keyvalue
errorCode0 for success, non-zero for failure. Always returned, but not really used if the throwOnError option is set to true.
errorMessageA description of the error. Always returned, but not really used if the throwOnError option is set to true.
imgA java BufferedImage object is returned if no output file is specified

Function Syntax

scaleWidth(objImage,inputFile,outputFile,newWidth,jpegCompression)

ParameterRequired?DefaultDescription
objImage YES - A java image object, or a blank string.
inputFile YES - File path or URL to an image, or a blank string.
outputFile YES - File path to write the output, or a blank string.
newWidth YES - Width in pixels of the resulting image.
jpegCompression NO defaultJpegCompression jpeg compression quality to use if writing a jpeg file. 0-100. 100 is the highest quality.

You must supply either an image object or a file path to a source image.

Example

<cfset imageCFC = createObject("component","image")>
<cfset imgInfo = imageCFC.scaleWidth("", "C:\Inetpub\wwwroot\myimage.jpg", "C:\Inetpub\wwwroot\tn_myimage.jpg",100)>
<img src="myimage.jpg" width="100" alt="resized image"/>