Description
Creates a ColdFusion image.
Returns
A ColdFusion image.
ImageNew([source, width, height, imageType, canvasColor])
cfimage, ImageCopy, ImageRead, ImageReadBase64, ImageSetDrawingColor, IsImageFile
ColdFusion 8: Added this function.
Parameter |
Description |
---|---|
source |
Optional. The source image on-disk or in-memory pathname, URL, a ColdFusion variable that is read into the new ColdFusion image, or a Java buffered image. |
width |
Optional. The width of the new ColdFusion image. Valid when the height is specified and the source is not. |
height |
Optional. The height of the new ColdFusion image. Valid when the width is specified and the source is not. |
imageType |
Optional. The type of the ColdFusion image to create:
|
canvasColor |
Optional. Color of the image canvas:
|
You can pass the ImageNew function any of the following parameters:
A Java buffered image.ColdFusion generates an error when the passed attributes cannot create a valid ColdFusion image.The ImageNew function and the{{cfimage}} read action support the SQL Server Image Column data type.To read Base64 images, use the ImageReadBase64 function.If the color value is a string, specify a supported named color; see the valid HTML named colors in cfimage. For a hexadecimal value, use the form "##xxxxxx" or "xxxxxx", where x = 0-9 or A-F; use two number signs or none.
Note: If you specify the ARGB image type, the image is white; however, if you specify RGB or grayscale, the image is black. To create blank images consistently, use the canvasColor parameter. |
<!--- Use the ImageNew function to create a 200x200-pixel image in ARGB format. ---> <cfset myImage = ImageNew("",200,200,"argb")> <cfimage action="writeTobrowser" source="#myImage#">
<!--- This example shows how to create a ColdFusion image from a BLOB in a database. ---> <cfquery name="GetBLOBs" datasource="myblobdata"> SELECT LastName,Photo FROM Employees </cfquery> <cfset i = 0> <table border=1> <cfoutput query="GetBLOBS"> <tr> <td> #LastName# </td> <td> <cfset i = i+1> <cfset myImage=ImageNew("#GetBLOBS.Photo#")> <cfset ImageWrite(myImage,"photo#i#.png")> </td> </tr> </cfoutput> </table>
<!--- This example shows how to create a ColdFusion image from a URL. ---> <cfset myImage = ImageNew("http://www.google.com/images/logo_sm.gif")> <cfset ImageWrite(myImage,"google_via_imagenew.png")> <img src="google_via_imagenew.png">
<!--- This example shows how to use the cffile tag to convert an image file to binary format and pass it as a variable to the ImageNew function. ---> <!---Use the cffile tag to read an image file, convert it to binary format, and write the result to a variable. ---> <cffile action = "readBinary" file = apple.jpg" variable = "aBinaryObj"> <!--- Use the ImageNew function to create a ColdFusion image from the variable. ---> <cfset myImage = ImageNew(aBinaryObj)>
<!--- This example shows how to use the cffile tag to write a ColdFusion image to a file. ---> <!--- Use the ImageNew function to create a ColdFusion image from a JPEG file. ---> <cfset myImage = ImageNew("../cfdocs/images/artgallery/aiden01.jpg")> <!--- Turn on antialiasing to improve image quality. ---> <cfset ImageSetAntialiasing(myImage,"on")> <!--- Resize the image. ---> <cfset ImageResize(myImage,"50%","")> <!--- Pass the image object to the cffile tag and write the result to a file on the local drive. ---> <cffile file="#myImage#" action="write" output="c:\test_myImage.jpg"> <cfimage action="writeToBrowser" source="#myImage#">
<!--- This example uses cfscript to pass a Java buffered image to the ImageNew function. ---> <cfscript> bufferedImage = createObject("java", "java.awt.image.BufferedImage"); bufferedImage.init(JavaCast("int", 100), JavaCast("int", 100), BufferedImage.TYPE_4BYTE_ABGR); myImage = imageNew(bufferedImage); </cfscript>