|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Resize image and Upload
Hello,
Please help me figure this out, my code to upload and resize an image works, but it cannot handle a large 5mega pxl image. It tries to upload the image first and then it resizes it. I need help for this code to first resize the image before it uploads. <!--- set the full path to the images folder ---> <cfset mediapath = ExpandPath("myimages")> <!--- set the desired image height ----> <cfset thumbsize = 75> <!--- set the desired image width ---> <cfset imagesize = 400> <cffile action="upload" filefield="FileUpload" destination="#MediaPath#" nameconflict="overwrite"> <!--- 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> <!--- end ---> Thanks. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Cold Fusion Development > Resize image and Upload |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|