in my flex app i upload files using a codlfusion script "upload.cfm" and it
works perfectly. i would like to take it a step further by allowing for image
manipulation while uploading so that when a person uploads an image of any
size, it is resized, croped and compressed to jpeg then saved on the server. i
would like to use imageCFC for this but dont know how. can someone please help
me? here is the upload script i use. how can i modify it to use imageCFC to
resize, crop and compress the image that is being uploaded? thanks alot
"upload.cfm"
<!---
Flex Multi-File Upload Server Side File Handler
This file is where the upload action from the Flex Multi-File Upload UI points.
This is the handler the server side half of the upload process.
--->
<!--- set the full path to the images folder --->
<cfset mediapath = expandpath('/IESTATE_V1/assets/agent_profilepics')>
<!--- set the desired image height ---->
<cfset thumbsize = 320>
<!--- set the desired image width --->
<cfset imagesize = 192>
<cftry>
<!---
Because flash uploads all files with a binary mime type
("application/ocet-stream") we cannot set cffile to accept specfic mime types.
The workaround is to check the file type after it arrives on the server and if
it is non desireable delete it.
--->
<cffile action="upload"
filefield="filedata"
<!--- destination="#ExpandPath('\')#realestate
portal\images\agent_pics\" --->
destination="#MediaPath#"
nameconflict="makeunique"
accept="application/octet-stream"/>
<!--- Begin checking the file extension of uploaded files --->
<cfset acceptedFileExtensions = "jpg,jpeg,gif,png"/>
<cfset filecheck =
listFindNoCase(acceptedFileExtensions,File.ServerFileExt)/>
<!--- read the image ---->
<cfimage name="uploadedImage"
source="#MediaPath#/#file.serverFile#" >
<!--- figure out which way to scale the image --->
<cfif uploadedImage.width gt uploadedImage.height>
<cfset thmb_percentage = (thumbsize / uploadedImage.width)>
<cfset percentage = (imagesize / uploadedImage.width)>
<cfelse>
<cfset thmb_percentage = (thumbsize / uploadedImage.height)>
<cfset percentage = (imagesize / uploadedImage.height)>
</cfif>
<!--- calculate the new thumbnail and image height/width --->
<cfset thumbWidth = round(uploadedImage.width *
thmb_percentage)>
<cfset thumbHeight = round(uploadedImage.height *
thmb_percentage)>
<cfset newWidth = round(uploadedImage.width * percentage)>
<cfset newHeight = round(uploadedImage.height * percentage)>
<!--- see if we need to resize the image, maybe it is already
smaller than our desired size --->
<cfif uploadedImage.width gt imagesize>
<cfimage action="resize"
height="#newHeight#"
width="#newWidth#"
source="#uploadedImage#"
destination="#MediaPath#/#file.serverFile#"
overwrite="true"/>
</cfif>
<!--- create a thumbnail for the image --->
<cfimage action="resize"
height="#thumbHeight#"
width="#thumbWidth#"
source="#uploadedImage#"
destination="#MediaPath#/thumbs/#file.serverFile#"
overwrite="true"/>
<!---
If the variable filecheck equals false delete the uploaded file immediatley as
it does not match the desired file types
--->
<cfif filecheck eq false>
<cffile action="delete"
file="#MediaPath#/#file.serverFile#"/>
</cfif>
<!---
Should any error occur output a pdf with all the details.
It is difficult to debug an error from this file because no debug information
is
diplayed on page as its called from within the Flash UI. If your files are not
uploading check
to see if an errordebug.pdf has been generated.
--->
<cfcatch type="any">
<cfdocument format="PDF" overwrite="yes"
filename="errordebug.pdf">
<cfdump var="#cfcatch#"/>
</cfdocument>
</cfcatch>
</cftry>