Avatar of lulu50
lulu50
Flag for United States of America asked on

Resize the images

Hi,

I need to resize my images before upload them to my folder.
How would I do this?

here's what I have so far:


<cfset numberoffields = 4>
<cfset targetDirectory = ExpandPath('.')&"\LoadImg\">
  <cfif isdefined("form.upload")>
    <cfset message = "">
    <cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
      <cfset filename = "form.file" & #i#>
      <cfif evaluate(variables.filename) neq "">
        <cffile action="UPLOAD" 
           destination="#targetDirectory#" 
           nameconflict="OVERWRITE" 
           filefield="#variables.filename#"/>
        <cfset message = message & ",File%20#i#%20(#file.serverfile#)%20was%20uploaded">
      <cfelse>
        <cfset message = message & ",File%20#i#%20was%20empty">
      </cfif>
    </cfloop>
    <cflocation url="PostAd.cfm?ChID=1&msg=#variables.message#">
   
 <cfelse>
     <cfif isdefined("url.msg")>
       <div style="color:#FF0000;">
       <cfloop list="#url.msg#" index="i">
         <cfoutput>#i#</cfoutput><br />
       </cfloop>
       </div>
    </cfif>

<form name="RTEDemo" action=""#CGI.script_name#"?ChID=1" method="post" onSubmit="return submitForm();" enctype="multipart/form-data">



     <cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
      <cfset filename = "file" & #i#>
      <input type="File" name="<cfoutput>#variables.filename#</cfoutput>" /><br />
      </cfloop>
  <input type="Submit" name="upload" value="upload">

</form>
</cfif>

Open in new window

ColdFusion Language

Avatar of undefined
Last Comment
lulu50

8/22/2022 - Mon
_agx_

Unfortunately I said that before I found out you weren't using CF8. I haven't used it much, but if you're on MX7 try ImageUtil.cfc http://imageutils.riaforge.org/ 


<cfset filename = "form.file" & #i#>
<cfif evaluate(variables.filename) neq "">

I'm not sure where you got that code from but a lot of it's not recommended.  For example, don't use evaluate. for dynamic variables just use:
<cfif form["form.file" & i] ... >
- don't overuse # signs. a lot of those # signs aren't necessary
<cfset message = message & ",File%20#i#%20(#file.serverfile#)%20was%20uploaded">

- don't use the FILE scope. it was deprecated years ago. Also no need to manually url escape values. Just use the URLEncodedFormat function
_agx_

Unfortunately I said that before I found out you weren't using CF8

In other words, ImageResize (and a lot of other functions) won't be available to you if you're using MX7 (are you ...?)  If you're on MX7 or earlier, try one of these instead

http://imageutils.riaforge.org/ 
http://www.opensourcecf.com/imagecfc/
www.alagad.com/projects.imageComponent
Brijesh Chauhan

You can also use CFX_OPENIMAGE tag, which can be found here http://www.kolumbus.fi/~kr0626/cfx_openimage/, we have been using this with CF 4.5 + and it works great...
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
lulu50

ASKER
_agx_:

I am using MX7
lulu50

ASKER
brijeshchauhan:

I download the zip files but I would I used it  on my project?
lulu50

ASKER
brijeshchauhan:

Can you please walk me through the installation

So, a short summary what to do…
1. Install the tag and all the other files to some directory
(I can do this)

2. set a system enviroment variable CFX_OPENIMAGE_FULLPATH with value of full
pathname to the installation folder
(I am not sure how to set the variable enviroment)

3. register the dll to Cold Fusion via CF admin page
(I am not sure how to register dll to cold fusion)

4. Try out the samples
(where is the sample that I can try I don't see them?)

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Brijesh Chauhan

3. register the dll to Cold Fusion via CF admin page

=====

GO to CF Administrator, look for EXTENSIONS on your left hand pannel, then click on CFX TAGS

Extensions > CFX Tags

On This page, click on Register C++ CFX tag

Then Enter the following

Tag Name -> CFX_OPENIMAGE
Server Library -> C:\cfx_openimage\cfx_openimage.dll

Then click Submit.

2. set a system enviroment variable CFX_OPENIMAGE_FULLPATH with value of full
pathname to the installation folder
(I am not sure how to set the variable enviroment)

===============

Right Click on My Computer -> Properties -> Advanced -> Enviroment Variables

Here you can add the EV

Brijesh Chauhan

Refer this screen shot for setting Enviroment Variable above

http://www.kolumbus.fi/~kr0626/cfx_openimage/snapshot.png
_agx_

@lulu50

You can use any of those 3 cfc's with MX7. You don't need to register anything. Just copy the files into your web root and it's ready to use. Resizing:

http://www.opensourcecf.com/imagecfc/docs/resize.cfm
<cfset imageCFC = createObject("component","image")>
<cfset imgInfo = imageCFC.resize("", "C:\Inetpub\wwwroot\myimage.jpg", "C:\Inetpub\wwwroot\myimage2.jpg",100,200)>
<img src="myimage2.jpg" width="100" height="200" alt="resized image to a specific width and height."/>
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Brijesh Chauhan

4. Try out the samples
(where is the sample that I can try I don't see them?)

=====

In your downloaded FOLDER, you will have a sub-folder called iml_examples, those are the ones which you can run and try.
ASKER CERTIFIED SOLUTION
_agx_

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Brijesh Chauhan

Installing the TAG is very easy and will NOT take you more than a couple of minutes. Also it's a very powerfull TAG written in C++, you can use it for doing LOT of Image Manupulations and functions, please read the TAG guid which is there in documentation folder...
_agx_

@lulu50 - you have the options. rather than drowning you out in a flurry of posts ;-) I'll leave it up to you to choose whichever one suits you best.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Brijesh Chauhan

From the options that _agx_ has suggested, I would recommend Image CFC -> http://www.opensourcecf.com/imagecfc/

I have used this on a LINUX box as CFX OPENIMAGE is not supported on LINUX, and IMAGE CFC worked really well and infact for us on that particular project, it performed better than the inbuild cfimage tag (FOR CF 8) which used to CRASH a lot while resizing.
_agx_

Personally I prefer alagad's. But for basic resizing they're all fine. Time for me to sleep. I'm sure brij will have more to say on it, lol. So you guys continue on without me. Night all!
lulu50

ASKER
agx_:

I like to use alagad's because it is simple. but I have an error that says:

It is looking for the component.  where can I get this component?

Could not find the ColdFusion Component Image.  
Please check that the given name is correct and that the component exists.  
 
The error occurred in xxx line 144
 
142 :
143 :
144 : <cfset myImage = CreateObject("Component","Image") />
145 :
146 :  <!---open the image to resize --->
 
Your help has saved me hundreds of hours of internet surfing.
fblack61
Brijesh Chauhan

where is your Image.cfc component ??
Brijesh Chauhan

You have to specify the complete page RELATIVE to web-root, say you have installed the tag in a directory called /webroot/alagad/Image.cfc, then you have to create object like

<cfset myImage = CreateObject("Component","alagad.Image") />
lulu50

ASKER
_agx_:

the links are broken.  I cannot access or download the zip file

"The alagad image component is equally simple. Just download it, unzip the files into your web root.
http://www.alagad.com/projects.imageComponent.Resize"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
lulu50

ASKER
I cannot open this site to download the component

http://www.alagad.com/downloads/ImageComponent.zip
SOLUTION
Brijesh Chauhan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
_agx_

the links are broken.  I cannot access or download the zip file
There must be something wrong with your connection.  All four links work fine.

http://www.alagad.com/projects.imageComponent > Select download
http://www.alagad.com/downloads/ImageComponent.zip   (Direct download link)
http://imageutils.riaforge.org/
http://www.opensourcecf.com/imagecfc/
lulu50

ASKER
Thank you guys I got it to work.

Great !!!!

Thank you both.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
lulu50

ASKER
Thank you