Skip to main content
May 21, 2013
Question

ImageScaletoFit Issue

  • May 21, 2013
  • 1 reply
  • 640 views

<tr><cfoutput query="myDirectory" maxrows="1">

<td align="center"><a href="#Name#">

<cfimage source="#Name#" name="Name1">

<cfset ImageScaleToFit(Name,200,"")><!---  ---><img src="#Name#" /><br />#Name#</a></td>

<cfif myDirectory.currentRow MOD 3 EQ 0>

</tr>

<tr>

</cfif></cfoutput>

Whenever I try the code above I get the following error "

Unable to cast an object of type java.lang.String to Image.

"

How can I use this tag and resize images that are stored in the variable Name and get them to display correctly?  HELP!

    This topic has been closed for replies.

    1 reply

    WolfShade
    Legend
    May 21, 2013

    You scale the image, first, then use CFIMAGE action="writetobrowser" to display it.

    ^_^

    May 21, 2013

    So how should it look then?

    WolfShade
    Legend
    May 21, 2013

    According to Adobe CF docs, resizing an image is done as:

    <cfimage
        required
        action = "resize"
        height = "number of pixels|percent%"
        source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#"
        width = "number of pixels|percent%"
        optional
        destination = "absolute pathname|pathname relative to the web root"
        isBase64 = "yes|no"
        name = "cfimage variable"
        overwrite = "yes|no">

    Then, writing it to the browser is like:

    <cfimage action="writetobrowser" source="#image name from first cfimage tag#" format="gif" id="yourID" />

    ^_^

    

    UPDATE: I just noticed ImageScaleToFit.  Sorry. Place the following between the first two tags I wrote:

    <cfset ImageScaleToFit(image name from first cfimage tag,options)>

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7975.html