You can create simple applications that automate image processes by using ColdFusion images.
Generating thumbnail images
The following example shows how to create a form for uploading images. A visitor to the site can use the form to upload an image file and generate a thumbnail image from it. You use ColdFusion image operations to perform the following tasks:
- Verify that the uploaded file is a valid image.
- Ensure that the height or the width of the image does not exceed 800 pixels.
- If the image is valid and within the size limits, generate a thumbnail version of the source image and save it to a file.
Enter the following code on the form page:
<!--- This code creates a form with one field where the user enters the image file to upload. ---> |
Enter the following code on the action page:
<cfset thisDir = expandPath(".")> |
Generating a gallery of watermarked images
The following example extracts images and information from the cfartgallery database. You use ColdFusion image operations to perform the following tasks:
- Verify that an image exists for records returned from the database.
- Display the text, SOLD! on images that have been sold.
- Resize images to 100 pixels, maintaining the aspect ratio of the source image.
- Add a 5-pixel border to the images.
- Display the modified images directly in the browser without writing them to files.
Example
<!--- Create a query to extract artwork and associated information from the cfartgallery database. ---> |
Using CAPTCHA to verify membership
The following example shows how to create a simple form to verify whether a person (rather than a computer generating spam) is registering to receive an online newsletter. You generate the CAPTCHA image from a random text string on the form page and verify the response on the action page.
Example
Enter the following code on the form page:
<!--- Set the length of the text string for the CAPTCHA image. ---> |
Enter the following code on the action page:
<!--- Verify whether the text entered by the user matches the CAPTCHA string. ---> |
Creating versions of an image
The following example shows how to create an application that lets you generate four versions of the same image, display the versions in a form, and choose which one to save. The application comprises three ColdFusion pages that perform the following tasks:
- Dynamically populate a drop-down list box from a database query.
- Use the cfimage tag to create a ColdFusion image from the title selected from the list. Use the ImageNew function to create three clones of the ColdFusion image. Use the ImageSharpen function to change the sharpness setting for each clone.
- Save the file chosen from the form to a new location.
Example
On the first form page, create a query that selects the artwork from the cfartgallery database and displays the titles in a pop-up menu:
<!--- Create a query to extract artwork from the cfartgallery database. ---> |
On the first action page, clone the original image three times, change the sharpness setting for each clone, and display the results:
<!--- Determine whether a valid image file exists. ---> |
On the second action page, save the selected image to the C drive:
<p>The image you have chosen has been saved.</p> |