Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Testing an images size, then resizing...can't get variables right.

Guest
Oct 26, 2011 Oct 26, 2011

Hi all,

Complete ColdFusion newbie who's taken over a massive website written in CF8.  I'm slowly fumbling my way through things but thought I should at least start using the forums for help a bit more than spending countless hours working stuff out on my own.

I've got the following code which checks an images size, then tries to resize if its too big.  It's of course failing with details below.  Any help would be great.  The code is:







<cfif FileExists("#SITE_PATH#/images/wines/bottles/big/#fileName#")>







<cfset bottleImage = "#SITE_PATH#/images/wines/bottles/big/#fileName#">






</cfif>






<cfif bottleImage.width gt 345>







<cfset imageScaleToFit(#bottleImage#,"250","")>







<img  src="#bottleImage#" border="0" alt="#prdName#">






</cfif>

I'm getting an error which states:

You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.            

I've just started learning Java at work so I understand that it thinks bottleImage is a String.  But then I'm asking it the test the Strings image size which of course doesn't work.  How do I feed into ColdFusion the actual image "object" so that it can then use methods based on it?

Thanks all!

Matt

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 27, 2011 Oct 27, 2011

You need to feed the path (physical file path or url) into the ImageNew() function. If the path represents a valid image, the function will load and return an image object. You can find more details and examples in the documentation

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_h-im_34.html#5179132

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_02.html#3532194

 

-Leigh

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 27, 2011 Oct 27, 2011

In addition to Owain's answer, it is this command,

<cfset bottleImage = "#SITE_PATH#/images/wines/bottles/big/#fileName#">

that creates the bottleImage variable.  Given the opening and closing double quotes, it's a string.

In future, when you get that type of error message, check the line number in the error message and see what variable was created.  Then cfdump that variable to see what it actually is.

By the way, here is the reverse of that error message:

Complex object types cannot be converted to simple values.

Troubleshooting remains the same.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 28, 2011 Oct 28, 2011

I think the problem isn't there fellows... it's rather the imagewitdh that wouldn be set

check http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Images_20.html

there you'll find <cfif ImageGetHeight(myImage) gt 800 or ImageGetWidth(myImage) gt 800> and more hints to make your script better.
also don't forget to read the image before that line
<cfimage action="read" source="#fileUpload.serverfile#" name="myImage">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 28, 2011 Oct 28, 2011

it's rather the imagewitdh that wouldn be set

No, the syntax imageObjectVariable.width is valid. The problem is the original code is not actually creating an image object, just a string.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 28, 2011 Oct 28, 2011

that's where the cfimage action read part comes in handy 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 28, 2011 Oct 28, 2011

As does the earlier one on imageNew()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2011 Oct 30, 2011

Well I've got it to at least not crash with an error, but instead now shows nothing as if something has gone wrong between the image and outputting the image via the src="xxxx".

Here's the code:

<cfif FileExists("#SITE_PATH#/images/wines/bottles/big/#fileName#")>

     <!-- <cfset bottleDisplay = ImageNew("#SITE_PATH#/images/wines/bottles/big/#fileName#")> -->

     <cfimage action="read" source="#SITE_PATH#/images/wines/bottles/big/#fileName#" name="bottleDisplay">  <--- Have tried both, neither makes a difference

</cfif>

<cfif bottleDisplay.width gt 345>

     <cfset imageScaleToFit(bottleDisplay,"250","")>

</cfif>

<img  src="#bottleDisplay#" border="0" alt="#prdName#">

I'm thinking it's something in the src line, but what am I to know?  It shows the ALT tag fun, just doesn't produce the image anywhere.  Any ideas??  Do I have to write the image back (I wouldn't have thought so....)

Thanks,

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 31, 2011 Oct 31, 2011
LATEST

Your src refers to a path and should refer to the url

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources