Resizes an image.
A structure containing the following fields:
| key | value |
|---|---|
| errorCode | 0 for success, non-zero for failure. Always returned, but not really used if the throwOnError option is set to true. |
| errorMessage | A description of the error. Always returned, but not really used if the throwOnError option is set to true. |
| img | A java BufferedImage object is returned if no output file is specified |
resize(objImage,inputFile,outputFile,newWidth,newHeight,preserveAspect,cropToExact,jpegCompression)
| Parameter | Required? | Default | Description |
|---|---|---|---|
| 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. Combine with newHeight=0 to scale the image to this specific width. |
| newHeight | YES | - | Height in pixels of the resulting image. Combine with newWidth=0 to scale the image to this specific width. |
| preserveAspect | NO | false | Specifies whether or not to preserve the aspect ratio of the original image. Setting this to true, when combined with a specified width and height, will scale the image to fit within the specified dimensions. The resulting image may be smaller in width or height. |
| cropToExact | NO | false | If this is set to true AND preserveAspect is set to true, the resized image is cropped to fit exactly within the specified dimensions. If preserveAspect is not true, this has no affect. |
| 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.
<cfset imageCFC = createObject("component","image")>
<cfset imgInfo = imageCFC.resize("", "C:\Inetpub\wwwroot\myimage.jpg", "C:\Inetpub\wwwroot\myimage2.jpg",100,200)>
<img src="myimage2.jpg" width="100" height="200" alt="resized image to a specific width and height."/>
<cfset imgInfo = imageCFC.resize("", "C:\Inetpub\wwwroot\myimage.jpg", "C:\Inetpub\wwwroot\myimage3.jpg",100,200,"true")>
<img src="myimage3.jpg" alt="resized image guaranteed to fit within a 100x200 space."/>
<cfset imgInfo = imageCFC.resize("", "C:\Inetpub\wwwroot\myimage.jpg", "C:\Inetpub\wwwroot\myimage4.jpg",100,0)>
<img src="myimage4.jpg" width="100" alt="resized image scaled to 100px wide."/>
<cfset imgInfo = imageCFC.resize("", "C:\Inetpub\wwwroot\myimage.jpg", "C:\Inetpub\wwwroot\myimage5.jpg",0,100)>
<img src="myimage5.jpg" height="100" alt="resized image scaled to 100px high."/>