Page 1 of 1

BlobToImage can not produce image from Oracle DB - help

Posted: 2011-08-29T11:06:34-07:00
by sdj
Hi there,

I am reading Oracle database of BLOB (images..don't know what format those are but trying to read and want to display or store it in a file.

my $test_image;
my $image=Image::Magick->new(magick=>'jpg', size =>'640x480',depth=>72);

$sql = "select my_image from all_images_BLOB where id_pk = 123";
$sth = $dbh->prepare( $sql );
$sth->execute();
$sth->bind_columns(undef,\$test_image);
while($sth->fetch()) {
$image->BlobToImage($test_image);
$image->Write('example_out.jpg');
}


$sth->finish();
$dbh->disconnect();

Somehow, I get a file with 0 bytes.

But when change one line in above code:
$image->Write('example_out.jpg'); to $image->Write('example_out.bmp);

I get Image but its all black.

I really appreciate your help in this,

Thank you in advance,
SDJ

Re: BlobToImage can not produce image from Oracle DB - help

Posted: 2011-10-09T11:58:02-07:00
by delilama
Just write out the blob. See what it looks like. Maybe your blob is in some different format, and this is why it's failing?

Re: BlobToImage can not produce image from Oracle DB - help

Posted: 2011-10-11T21:59:21-07:00
by jchimene
I've been doing this from MySQL, but the principal is the same.

I use $dbh->selectall_arrayref(), but the end result should be the same

Couple questions:
1) Shouldn't you be calling new() for each image?
2) You're not checking the result of the Write. There may be a return result that will provide A Clue
LOGDIE is from Log::Log4perl qw(:easy);
$image->BlobToImage( $result->[$v]{cargo} );
eval {
LOGDIE $! unless $image->Write( $file[0] ) > 0;
};
if ($@)
{
LOGDIE qq/Cannot write image $file[0]: $@\n/;
}