This should solve your problem. It's a function from one of my CF Components it 
will return various image properties including the width and height (unless 
it's CYMK, but then it will let you know that too). 

Put the function below in a CFC.

        <cffunction name="get_image_properties" returntype="any" 
access="public" output="false">
                <cfargument name="image_file" type="string" required="true" />
                <cftry>
                        <cfscript>
                          jFileIn = 
createObject("java","java.io.File").init(arguments.image_file);
                          ImageInfo = StructNew();
                          ImageObject = 
createObject("java","javax.imageio.ImageIO").read(jFileIn);
                          imageFile = CreateObject("java", "java.io.File"); 
                          imageFile.init(arguments.image_file); 
                          sizeb = imageFile.length(); 
                          sizekb = numberformat(sizeb / 1024, "999999999.99");
                          sizemb = numberformat(sizekb / 1024, "99999999.99");
                          get_imginfo = StructNew();
                          get_imginfo.ImgWidth = ImageObject.getWidth();
                          get_imginfo.ImgHeight = ImageObject.getHeight();
                          get_imginfo.ImageType = 
ImageObject.getColorModel().getColorSpace().getType();
                          if (get_imginfo.ImageType eq 9) {
                                get_imginfo.ImageType="CYMK";}
                                else if (get_imginfo.ImageType eq 5) {
                                get_imginfo.ImageType="RGB";}
                                else {get_imginfo.ImageType="UNKNOWN";};
                          get_imginfo.SizeKB = sizekb;
                          get_imginfo.SizeMB = sizemb;
                          return get_imginfo;
                        </cfscript>
                        <cfcatch type = "any">
                                <cfscript>
                                get_imginfo = StructNew();
                                get_imginfo.ImgWidth = 0;
                                get_imginfo.ImgHeight = 0;
                                get_imginfo.SizeKB = 0;
                                get_imginfo.SizeMB = 0;
                                get_imginfo.ImageType = "UNKNOWN";
                                return get_imginfo;
                                </cfscript>
                        </cfcatch>
                </cftry>
        </cffunction>


Call the function with this:

<cfinvoke component="PATHTOCOMPONENT.CFCFILENAME" method="get_image_properties" 
returnVariable="image_properties">
    <cfinvokeargument name="image_file" valueTHE-FULL-PATH-TO-THE-IMAGE-FILE">
</cfinvoke>

To see what values are returned so you can determine what you have to use do:

<cfdump var="# image_properties #">



Robert Harrison 
Director of Interactive Services

Austin & Williams
Advertising I Branding I Digital I Direct  
125 Kennedy Drive,  Suite 100   I  Hauppauge, NY 11788
T 631.231.6600 X 119   F 631.434.7022   
http://www.austin-williams.com

Blog:      http://www.austin-williams.com/blog
Twitter:  http://www.twitter.com/austin_williams 


-----Original Message-----
From: Dan Baughman [mailto:dan.baugh...@gmail.com] 
Sent: Tuesday, January 15, 2013 11:50 PM
To: cf-talk
Subject: Re: cfimage error


cfimage is really quite buggy... it has file locking issues.
you have to fiddle with the tag and function version until something works 
reliably in a high demand environment.  It is truthfully only marginally better 
than the native java stuff.

On Tue, Jan 15, 2013 at 3:59 PM, Tim Do <t...@wng.com> wrote:
>
> The images are all named correctly since I'm able to pull the images up and 
> display them.
> The coldfusion server that the cfimage code resides on is calling the image 
> from another server. I verified all permissions and even added everyone full 
> access to test and it still didn't work. I created a virtual directory to the 
> image server and the cfimage tag started working again. I'm not sure what 
> security differences are between the methods but the virtual directory fixed 
> my issue.
>
> -----Original Message-----
> From: Bill Moniz [mailto:hydro.b...@gmail.com]
> Sent: Tuesday, January 15, 2013 2:13 PM
> To: cf-talk
> Subject: Re: cfimage error
>
>
> Just because I ran into this CFimage problem yesterday... Are the images by 
> any change named with the wrong extension?  For example, a PNG inmage 
> mistakenly named with a JPG extension?  If you examine the first bit of the 
> file in a hex editor, you can see the difference.
>
> Cheers.
>
> On 16 January 2013 08:57, Tim Do <t...@wng.com> wrote:
>
>>
>> All images are RGB/BW no CMYK.
>>
>> -----Original Message-----
>> From: Robert Harrison [mailto:rob...@austin-williams.com]
>> Sent: Tuesday, January 15, 2013 1:48 PM
>> To: cf-talk
>> Subject: RE: cfimage error
>>
>>
>> Is the image CYMK?  That could cause a problem.
>>
>>
>> Robert Harrison
>> Director of Interactive Services
>>
>> Austin & Williams
>> Advertising I Branding I Digital I Direct
>> 125 Kennedy Drive,  Suite 100   I  Hauppauge, NY 11788 T 631.231.6600 X
>> 119   F 631.434.7022 http://www.austin-williams.com
>>
>> Blog:      http://www.austin-williams.com/blog
>> Twitter:  http://www.twitter.com/austin_williams
>>
>> -----Original Message-----
>> From: Tim Do [mailto:t...@wng.com]
>> Sent: Tuesday, January 15, 2013 2:34 PM
>> To: cf-talk
>> Subject: cfimage error
>>
>>
>> I have this bit of code that used to work in the past... but now I'm
>> getting:
>>
>> An exception occurred while trying to read the image.
>>
>> javax.imageio.IIOException: Can't get input stream from URL!
>>
>> I verified that the image is still there and permissions are still 
>> the same. I'm able to display the image fine. We're on cf9.
>>
>> <cfimage source="#getImage.imgName#" action="info"
>> structName="FlrPlnInfo">
>>
>>
>>
>> I'm just trying to get the width of the image. So I tried to use code 
>> below but just getting -1 for width and height.
>>
>> <cfobject type="JAVA" action="Create" name="tk"
>>           class="java.awt.Toolkit">
>> </cfobject>
>> <cfobject type="JAVA" action="Create" name="img"
>>           class="java.awt.Image">
>> </cfobject>
>> <cfscript>
>> img = tk.getDefaultToolkit().getImage("#getImage.imgName#");
>> width = img.getWidth();
>> height = img.getHeight();
>> </cfscript>
>> <cfoutput>#width#<br />#height#</cfoutput>
>>
>> Thanks!
>>
>>
>>
>>
>>
>>
>
>
>
> 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353927
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to