Small tutorial on how to re size an image with ColdFusion.
First we will create a form where you can upload the image.
Lets call it index.cfm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table border="0" cellpadding="0" cellspacing="1" width="500" align="center"> <cfform action="picture_add.cfm" name="AddPic" method="post" enctype="multipart/form-data"> <tr> <td align="right" class="Copy" valign="top">Photo:</td> <td align="left" class="Copy" valign="top"> <cfinput type="file" name="PICTURE" required="no"> </td> </tr> <tr> <td> </td> <td align="left"> <cfinput type="submit" name="Submit" value="Submit"> </td> </tr> </cfform> </table> </body> </html>
As you can see in our <CFFORM ></CFFORM >tags we call the page picture_add.cfm.
So when you click on submit button the picture_add.cfm page will be called.
Lets code the picture_add.cfm page.
Ok we have now coded the picture_add.cfm page
Lets go through it step by step.
First we start off with a parameter called "Error".
Ill explain to you later what this variable does.
We then have a cfif statement.
This statement tests the picture field in the index.cfm, it sees were there is something to upload.
The second statement is there for error handling, a try statement if anything is wrong with image an error should be thrown.
Our third field is where the original picture will be uploaded it will be sent to location chosen by you.
Your accept types tell you what file extensions to accept.
Nameconflict will tell coldfusion what to do if there are two images with the same.
In the <cfimage> tag the following occurs.
The pictures get re-sized and uploaded to your specific directory.
You will need to manipulate the sizes of an image because it will look weird if the height and width is not exact.
Next there is a catch statement to catch all errors.
Remember the variable that Error we declared right in the beginning this is where we use it.
We use another if statement to test this value.
We have a cfelse statement this will execute if our error = ""(nothing).
Then we have a query that will insert the picture into a database.
I hope this made sense and helped.