Whatever message this page gives is out now! Go check it out!
Task | Functions and tags |
Create a ColdFusion image from an existing image file. | cfimage tag or the ImageNew function |
Create a blank image from scratch. | ImageNew function |
Create a ColdFusion image from BLOB data in a database. | ImageNew function with the cfquery tag |
Create a ColdFusion image from a binary object. | cffile tag with the ImageNew function |
Create a ColdFusion image from a Base64 string. | ImageReadBase64 function and the ImageNew function or the cfimage tag |
Create a ColdFusion image from another ColdFusion image. | ImageCopy function with the ImageWrite function or the Duplicate function, or by passing the image to the ImageNew function or the cfimage tag |
<cfimage source="../cfdocs/images/artgallery/jeff01.jpg" name="myImage"> |
<cfimage source="#myImage#" action="write" destination="test_myImage.jpg"> |
<cfimage source="http://www.google.com/images/logo_sm.gif" action="write"
destination="c:\images\logo_sm.gif"><cfimage source="#myImage#" action="write" destination="images/jeff01.jpg" overwrite="yes"> |
<cfset myImage=ImageNew("../cfdocs/images/artgallery/jeff01.jpg")> |
<cfimage source="../cfdocs/images/artgallery/jeff01.jpg" name="myImage"> |
<cfset myImage=ImageNew("../cfdocs/images/artgallery/jeff01.jpg")>
<cfset ImageWrite(myImage,"myImageTest.png")><cfimage source="../cfdocs/images/artgallery/jeff01.jpg" name="myImage">
<cfimage source="#myImage#" action="write" destination="myImageTest.png"><cfset myImage=ImageNew("",300,200)> |
<cfset myImage=ImageNew("",200,300,"rgb")> |
<cfset x = ImageNew("c:\abc.jpg")>
<cfset y = ImageNew(x)><!--- 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 = "jeff05.jpg" variable = "aBinaryObj">
<!--- Use the ImageNew function to create a ColdFusion image from the variable. --->
<cfset myImage=ImageNew(aBinaryObj)><!--- Use the cfquery tag to retrieve employee photos and last names from the database. --->
<cfquery
name="GetBLOBs" datasource="myblobdata">
SELECT LastName,Image
FROM Employees
</cfquery>
<cfset i = 0>
<table border=1>
<cfoutput query="GetBLOBs">
<tr>
<td>
#LastName#
</td>
<td>
<cfset i = i+1>
<!--- Use the cfimage tag to write the images to PNG files. --->
<cfimage source="#GetBLOBs.Image#" destination="employeeImage#i#.png"
action="write">
<img src="employeeImage#i#.png"/>
</td>
</tr>
</cfoutput>
</table><!--- Use the cfquery tag to retrieve all employee photos and employee IDs from a database. --->
<cfquery name="GetBLOBs" datasource="myBlobData">
SELECT EMLPOYEEID, PHOTO FROM Employees
</cfquery>
<!--- Use the ImageNew function to create a ColdFusion images from the BLOB data that was
retrieved from the database. --->
<cfset myImage = ImageNew(GetBLOBs.PHOTO)>
<!--- Create thumbnail versions of the images by resizing them to fit in a 100-pixel square,
while maintaining the aspect ratio of the source image. --->
<cfset ImageScaleToFit(myImage,100,100)>
<!--- Convert the images to JPEG format and save them to files in the thumbnails subdirectory,
using the employee ID as the filename. --->
<cfimage source="#myImage#" action="write"
destination="images/thumbnails/#GetBLOBs.EMPLOYEID#.jpg"><!--- This example shows how to create a ColdFusion image from a Base64 string with headers
(used for display in HTML). --->
<cfimage source="data:image/jpg;base64,/9j/4AAQSkZJRgABAQA.............."
destination="test_my64.jpeg" action="write" isBase64="yes">
<!--- This example shows how to use the cfimage tag to write a Base64 string without headers. --->
<cfimage source="/9j/4AAQSkZJRgABAQA.............." destination="test_my64.jpeg"
action="write" isBase64="yes"><!--- This example shows how to use the ImageReadBase64 function to read a Base64 string
with headers. --->
<cfset myImage=ImageReadBase64("data:image/jpg;base64,/9j/4AAQSkZJRgABAQA..............")>
<!--- This example shows how to read a Base64 string without headers. --->
<cfset myImage=ImageReadBase64("/9j/4AAQSkZJRgABAQA..............")><!--- Use the cfimage tag to create a ColdFusion image from a JPEG file.
--->
<cfimage source="../cfdocs/images/artgallery/lori05.jpg" name="myImage">
<!--- Turn on antialiasing to improve image quality. --->
<cfset ImageSetAntialiasing(myImage)>
<!--- Copy the rectangular area specified by the coordinates (25,25,50,50) in the image to
the rectangle beginning at (75,75), and return this copied rectangle as a new ColdFusion
image. --->
<cfset dupArea = ImageCopy(myImage,25,25,50,50,75,75)>
<!--- Write the new ColdFusion image (dupArea) to a PNG file. --->
<cfimage source="#dupArea#" action="write" destination="test_myImage.png" overwrite="yes"><!--- Use the ImageNew function to create a ColdFusion image from a JPEG file. --->
<cfset myImage=ImageNew("../cfdocs/images/artgallery/paul01.jpg")>
<!--- Turn on antialiasing to improve image quality. --->
<cfset ImageSetAntialiasing(myImage)>
<!--- Use the Duplicate function to create three clones of the ColdFusion image. --->
<cfset cloneA=Duplicate(myImage)>
<cfset cloneB=Duplicate(myImage)>
<cfset cloneC=Duplicate(myImage)>
<!--- Create a grayscale version of the image. --->
<cfset ImageGrayscale(cloneA)>
<!--- Create a thumbnail version of the image. --->
<cfset ImageScaleToFit(cloneB,50,"")>
<!--- Create an enlarged version of the image. --->
<cfset ImageResize(cloneC,"150%","")>
<!--- Write the images to files. --->
<cfset ImageWrite(myImage,"paul01.jpg","yes")>
<cfset ImageWrite(cloneA,"paul01_bw.jpg","yes")>
<cfset ImageWrite(cloneB,"paul01_sm.jpg","yes")>
<cfset ImageWrite(cloneC,"paul01_lg.jpg","yes")>
<!--- Display the images. --->
<img src="paul01.jpg">
<img src="paul01_bw.jpg">
<img src="paul01_sm.jpg">
<img src="paul01_lg.jpg"><!--- Use the cfimage tag to create a ColdFusion image (myImage) and make a copy of it (myImageCopy). --->
<cfimage source="../cfdocs/images/artgallery/paul01.jpg" name="myImage">
<cfimage source="#myImage#" name="myImageCopy">
<!-- Use the ImageNew function to make a copy of myImage called myImageCopy2. --->
<cfset myImageCopy2 = ImageNew(myImage)>