Skip to main content
WolfShade
Legend
September 28, 2015
Question

ImageResize: unable to cast an object of [B to image

  • September 28, 2015
  • 3 replies
  • 956 views

Hello, all,

On a personal project at home, I'm trying to use ImageResize to resize an image pulled from a BLOB in a MySQL database.  I'm getting an error message "unable to cast an object of [B to image."  Have not a clue what that means. 

Here's my code..

SELECT imageBLOB, imageWidth, imageHeight

FROM r_images

WHERE imageID = <cfqueryparam value="#arguments.thisID#" cfsqltype="cf_sql_varchar" />

and..

variables.thisPicQry = new components.PICTURES().getAlbumPic('#trim(url.id)#');

ImageResize(variables.thisPicQry.imageBLOB,"50%","");

variables.thisImg = variables.thisPicQry.imageBLOB;

I've never used ImageResize() before.  The data from the database is already a binary; so what am I doing incorrectly?

V/r,

^_^

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    October 2, 2015

    Shouldn't imageResize() have at least 3 arguments? In any case, I cannot see what's going on with:

    variables.thisPicQry = new components.PICTURES().getAlbumPic('#trim(url.id)#'); 

    and

    variables.thisPicQry.imageBLOB

    If the name of the query is variables.thisPicQry then you could just do something like

    <cfset thisImg = imageNew(variables.thisPicQry.imageBLOB)>

    <cfset imageResize(thisImg, "50%", "50%")>

    Inspiring
    October 2, 2015

    Yeah it should have 3 arguments. I missed the last one off by accident when I typed my reply. Copy and paste fail!

    If that is still not working, then why doesnt it work. What happens and what are you expecting?

    WolfShade
    WolfShadeAuthor
    Legend
    October 2, 2015

    Unfortunately, things at work have exploded (new public site launched; it was showcased at a huge convention in DC; end of FY; end of contract, then recompete; frenzy of getting new CACs for everyone in my dept) and I haven't had a chance to breathe, much less get back to this project at home. 

    I'll try that as soon as I can and report back.

    Thanks, BKBK‌ and haxtbh‌, for your help.

    V/r,

    ^_^

    Inspiring
    September 29, 2015

    Create an image instance first and assign the blob to it, then manipulate the image.

    So something like this :

    theImage = ImageNew(variables.thisPicQry.imageBlob);

    ImageResize(theImage, "50%");

    Are you just displaying this on a web page though? If so and the image are not huge in size, dont use Coldfusion to resize it, just use CSS.

    WolfShade
    WolfShadeAuthor
    Legend
    September 29, 2015

    The images range anywhere from 160k to ~400k, so if resizing it can bring it down, perfect - less network traffic, at the very least.  This is for a "kind of" thumbnail - it's the picture that represents the album it is in, so I don't want to shrink the image before storing in the database.

    I did try that, earlier, but it didn't work.  I'll see about trying, again.

    Thanks for your reply!

    V/r,

    ^_^

    WolfShade
    WolfShadeAuthor
    Legend
    September 29, 2015

    Do I need to convert the BLOB to something else in order to use ImageResize()?  If I don't use ImageResize(), the picture displays, but it's going way past the DIV boundary (it's being used as a background image.)

    V/r,

    ^_^