Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image resize with image.cfc 2

Status
Not open for further replies.

RobHat

Technical User
Nov 30, 2007
91
GB
Hi guys,
I'm hoping someone can help me. I have a problem where when I upload a file i need to also resize it. I have the upload sorted and have a way of renaming it, after these it enters the name into the db. I am trying to use imagecfc from
When I test the code it uploads, and renames ok and also sends the name to the db. but does not adjust the size. The strange thing is the code to resize is also the code to rename and it renames it fine.

My code is this:

<!--- Upload Pic --->
<CFSET today = DateFormat(Now(),"DDMMYY")>
<CFSET now = TimeFormat(Now(),"HHmmss")>
<cfif isdefined("form.submit_upload")>
<cfif isdefined("FORM.filename1") AND #FORM.filename1# NEQ "">
<cffile action="UPLOAD" filefield="filename1" destination="DIRPATH\db_images\" nameconflict="MAKEUNIQUE">
<CFSET img1= AgentLOGIN& #today# & #now#>
<CFSET img=ListAppend(img1,FILE.ServerFileExt,".")>
<cfset imageCFC = createObject("component","image")>
<cfset imgInfo = imageCFC.scaleWidth("", "*DIRPATH*\db_images\#CFFILE.ServerFile#", "*DIRPATH*\db_images\#img#", 100, 60)>
<cfset form.filename1="#img#">
<cfelse>
''
</cfif>
</cfif>

I have the cfc files in I dunno if that makes a difference. I was told that it did not matter where they are placed under folder.

I struggling to figure out why this is not working. I have tryed a few different ways to write the code using a few different tutorials and they have all made the same results which means the error is me lol. Any help or guidance will be appreciated.

Thanks

Rob
 
Quick update, I think the problem is coming from the page not being able to locate the image.cfc file.

<cfset imageCFC = createObject("component","image")> was the coding i was using but have since tried:

<cfset imageCFC = createObject("component","cfc.imagecfc-2.19.image")> which did not work I assumed because of the . in the folder name. So I renamed the folder to imagecfc219 and I still get the same error. which is:

Could not find the ColdFusion Component image.
Please check that the given name is correct and that the component exists.

The error occurred in D:\aahelmsites_coldfusion\invest-worldwide.com\ line 42
Called from D:\aahelmsites_coldfusion\invest-worldwide.com\ line 37
Called from D:\aahelmsites_coldfusion\invest-worldwide.com\ line 1

40 : <CFSET img1= AgentLOGIN& #today# & #now#>
41 : <CFSET img=ListAppend(img1,FILE.ServerFileExt,".")>
42 : <cfset imageCFC = createObject("component","image")>
43 : <cfset imgInfo = imageCFC.scaleWidth("", "*DIRPATH*\db_images\#CFFILE.ServerFile#", "*DIRPATH*\db_images\#img#", 100, 60)>
44 : <cfset form.filename1="#img#">
 
Ok You can all tell me what a pain in the neck I am but I now have this working fine. I changed from using the image.cfc to using one called iedit. I have not looked at it properly yet but it does not look as powerful as image.cfc but it does the job. Image.cfc would have been a great extension if I could of got it working. (Note I am the problem not the software). The code below is the final working code for future reference if anybody needs it.

<!--- Upload Pic --->
<CFSET today = DateFormat(Now(),"DDMMYY")>
<CFSET now = TimeFormat(Now(),"HHmmss")>
<cfif isdefined("form.submit_upload")>
<cfif isdefined("FORM.filename1") AND #FORM.filename1# NEQ "">
<cffile action="UPLOAD" filefield="filename1" destination="*DIRPATH*\db_images\" nameconflict="MAKEUNIQUE">
<CFSET img1= AgentLOGIN& #today# & #now#>
<CFSET img=ListAppend(img1,FILE.ServerFileExt,".")>
<!--- Create iEdit Object ---->
<cfset myImage = CreateObject("Component", "iEdit")>
<!--- Select the original image ---->
<cfset myImage.SelectImage("*DIRPATH*\db_images\#CFFILE.ServerFile#")>
<!--- Scale the image ---->
<cfset myImage.scaleToFit(250,250)>
<!--- Output the image ---->
<cfset myImage.output("*DIRPATH*\db_images\#img#", "jpg",80)>
<cfset form.filename1="#img#">
<cfelse>
''
</cfif>
</cfif>

I had to put the iedit.cfc in the same folder as the page itself in order to get my pages to find the .cfc file. Does anybody know why this might be? The only other code used was to submit the form and insert the filename into the db.

Rob

P.S I got I iedit.cfc from Has a good simple set of instructions attached.
 
What a pain in the neck you are! Just joking ;) IMO posting a resolution is a good thing, even if you solved your own problem. Never know when it might help someone else.

Anyway, can you post the version of CF you are using? Maybe someone can try the code when time allows. They might be able to spot the problem, or at least confirm they had the same issue.

 
Yeah am using cf8 dev edition but I think the server my site runs on is 7. Another problem I have is that I need to multiple uploads. now before I added the resize feature it worked fine just repeating the code with a few name changes but with this code I have no such luck. It sends pics with the right name but no resize. Any ideas??? I have tried the code below and the same but with the myimage name in <cfset myImage = CreateObject("Component", "iEdit")> to myimage2 and throughout the rest of the code but no luck.

Thanks for any help in advance.

Rob

Code:

<!--- Upload Pic --->
<CFSET today = DateFormat(Now(),"DDMMYY")>
<CFSET now = TimeFormat(Now(),"HHmmss")>

<!--- Filename1 --->
<cfif isdefined("form.submit_upload")>
<cfif isdefined("FORM.filename1") AND #FORM.filename1# NEQ "">
<cffile action="UPLOAD" filefield="filename1" destination="*DIRROOT*\db_images\" nameconflict="MAKEUNIQUE">
<CFSET img1= AgentLOGIN& #today# & #now#>
<CFSET img=ListAppend(img1,FILE.ServerFileExt,".")>

<!--- Create iEdit Object ---->
<cfset myImage = CreateObject("Component", "iEdit")>

<!--- Select the original image ---->
<cfset myImage.SelectImage("*DIRROOT*\db_images\#CFFILE.ServerFile#")>

<!--- Scale the image ---->
<cfset myImage.scaleToFit(250,250)>

<!--- Output the image ---->
<cfset myImage.output("*DIRROOT*\db_images\#img#", "jpg",80)>
<cfset form.filename1="#img#">
<cfelse>
''
</cfif>
</cfif>

<!--- Filename2 --->
<cfif isdefined("form.submit_upload")>
<cfif isdefined("FORM.filename2") AND #FORM.filename2# NEQ "">

<cffile action="UPLOAD" filefield="filename2" destination="*DIRROOT*\db_images\" nameconflict="MAKEUNIQUE">
<CFSET img2= AgentLOGIN& #today# & #now# + 2 >
<CFSET img1=ListAppend(img2,FILE.ServerFileExt,".")>

<!--- Create iEdit Object ---->
<cfset myImage = CreateObject("Component", "iEdit")>

<!--- Select the original image ---->
<cfset myImage.SelectImage("d:\aahelmsites_coldfusion\invest-worldwide.com\
<!--- Scale the image ---->
<cfset myImage.scaleToFit(250,250)>

<!--- Output the image ---->
<cfset myImage.output("*DIRROOT*\#img1#", "jpg",80)>
<cfset form.filename2="#img1#">
<cfelse>
''
</cfif>
</cfif>
 
Are you saying the resize code works on a single image, but not for multiple images.. or that resizing doesn't work at all?

Also, does the component allow you to read/write to the same file name? Some components force you to use a different name when resizing.
 
Sorry did'nt explain it very well. The image resize worked fine on the first file. but as soon as I duplicated it to the second it failed on both. still renamed and uploaded the file but no resize. The component should allow you to write to the same file name. I have just been trying to find where it says it but am sure I read in the documentation.

Thanks

Rob
 
Odd. Did you try a resize only test with two images? I typed this quickly so check the variable names carefully.

Code:
<cfset myImage = CreateObject("Component", "iEdit")>
<cfset myImage.SelectImage(pathToTestImage1)>
<cfset myImage.scaleToFit(250,250)>
<cfset myImage.output( pathToTestImage1, "jpg",80)>

... repeat for TestImage2

If that doesn't work, try creating only one iEdit object and reusing it for both images

Code:
<cfset myImage = CreateObject("Component", "iEdit")>
<!--- resize image 1 --->
<cfset myImage.SelectImage(pathToTestImage1)>
<cfset myImage.scaleToFit(250,250)>
<cfset myImage.output( pathToTestImage1, "jpg",80)>
<!--- resize image 2 --->
<cfset myImage.SelectImage(pathToTestImage2)>
<cfset myImage.scaleToFit(250,250)>
<cfset myImage.output( pathToTestImage2, "jpg",80)>
 
Thanks for coming back so quickly. I used the following code and it uploaded the files saved them as img1.jpg and img2.jpg. It also resized both images to the correct size. It works ok here but I am really stuck as to why it works here but not on the other page???

<cfif isdefined("form.submit")>
<cfif isdefined("FORM.filename1") AND #FORM.filename1# NEQ "">
<cffile action="UPLOAD" filefield="filename1" destination="*DIRPATH*\db_images\" nameconflict="MAKEUNIQUE">
<cfset myImage = CreateObject("Component", "iEdit")>
<cfset myImage.SelectImage("*DIRPATH*\db_images\#CFFILE.ServerFile#")>
<cfset myImage.scaleToFit(250,250)>
<cfset myImage.output("*DIRPATH*\db_images\img1.jpg", "jpg",80)>
</cfif>
</cfif>
<cfif isdefined("form.submit")>
<cfif isdefined("FORM.filename2") AND #FORM.filename2# NEQ "">
<cffile action="UPLOAD" filefield="filename2" destination="*DIRPATH*\db_images\" nameconflict="MAKEUNIQUE">
<cfset myImage = CreateObject("Component", "iEdit")>
<cfset myImage.SelectImage("*DIRPATH*\db_images\#CFFILE.ServerFile#")>
<cfset myImage.scaleToFit(250,250)>
<cfset myImage.output("*DIRPATH*\db_images\img2.jpg", "jpg",80)>
</cfif>
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="test.cfm" method="post" enctype="multipart/form-data" name="testupload">
<input name="filename1" type="file" />
<br />
<input name="filename2" type="file" />
<br />
<input name="submit" type="submit" value="submit" />
</form>
</body>
</html>
 
So you're saying the same works on CF8 but not on the other site (MX7)?

Did you try the simple test in my last post?
 
SetsunaMudo, what a cool cfc. If it saves me the pains of installing imagemagic and figuring out how to get ColdFusion to use it, then I'm all for it. I know your the one looking for help, but star for you... :)

[plug=shameless]
[/plug]
 
Thanks Jstreich.

Hi cfstarlight no it works fine on both. Sorry i should be explaining this beter. The upload originally is on a page with many other fields to enter into the db. The code in the last post i made kinda used your idea for a simple test. I created a brand new page with only that image upload function in mind and it worked ok with multiple upload and resize. I then changed the name in order to rename it and it too worked fine. Meaning there is something on that page that maybe causing a problem.
 
Meaning there is something on that page that maybe causing a problem.

Yes, if the upload/reload works without the other "stuff" then it must be a problem with the other "stuff" on that page.
 
Ok I got it sorted in the end. Still can't figure out why it did'nt work but I rewrote the code fresh and it worked fine. must have been something small and yet important. Tomorrow I will finish this thread off with the final working code and a brief set of instructions in case any body needs it for reference in future.

Thanks for all the help.

Rob
 
Been following this thread in anticipation of a final resolution...now eagerly awaiting your final working code and instructions!
 
HI sorry mate have been away for a few days I will get this up for you tomorrow when I have some time.

Sorry to keep you waiting.

Rob
 
No worries. I kinda got it working on my local development server...now if I can successfully transition to my remote...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top