ColdFusion 9.0 Resources |
ImageNewParameters
UsageYou can pass the ImageNew function any of the following parameters:
ExampleExample 1 <!--- Use the ImageNew function to create a 200x200-pixel image in ARGB format. ---> <cfset myImage = ImageNew("",200,200,"argb")> <cfimage action="writeTobrowser" source="#myImage#"> Example 2 <!--- 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> Example 3 <!--- 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"> Example 4 <!--- 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)> Example 5 <!--- 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#"> Example 6 <!--- 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> |