[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

RMagick problem: Image::read works well but Image::from_blob fails

Mike Meng

9/16/2006 3:45:00 PM

Hi all,
I want to determine the geometry of an image. The image file may be
in local harddisk or on web. So I use open-uri and
Magick::Image::from_blob to do that work, here is the code:

open('<path or URI of image file>') { |f|
image = Magick::Image::from_blob(f.read).first
puts "Width: #{image.columns}; Height: #{image.rows}"
}

For most of the cases, this works well. However, we I tried to read an
JPEG generated by my Ricoh Caplio digital camera, it failed and emitted
these message:

---------- code ----------
E:/workspace/ruby/idapted/testrmg.rb:6:in `from_blob': JPEG datastream
contains
no image `' (Magick::ImageMagickError)
....
-----------------------------

Surprisingly enough, if I use Magick::Image::read method to read the
same image file directly from harddisk, everything is fine, here is the
code:
---------- code ----------
g = Magick::Image::read('<local file only>').first
puts "Width: #{g.columns}; Height: #{g.rows}"
-----------------------------

Why do Image::read and Image::from_blob make differeces? How to
determine the geometry of a remote image?

Any comment is appreciated. Thanks!

4 Answers

Paul Lutus

9/16/2006 4:06:00 PM

0

Mike Meng wrote:

/ ...

> Why do Image::read and Image::from_blob make differeces? How to
> determine the geometry of a remote image?

As I discovered while writing my Web editor Arachnophilia, there is plenty
of variation in the construction of JPG images, and not all the readers
know all the constructions. The best thing to do is test the software with
a large number of images before putting it in to service.

BTW please try for a more succinct subject line.

--
Paul Lutus
http://www.ara...

Tim Hunter

9/16/2006 4:22:00 PM

0

Mike Meng wrote:
> Hi all,
> I want to determine the geometry of an image. The image file may be
> in local harddisk or on web. So I use open-uri and
> Magick::Image::from_blob to do that work, here is the code:
>
> open('<path or URI of image file>') { |f|
> image = Magick::Image::from_blob(f.read).first
> puts "Width: #{image.columns}; Height: #{image.rows}"
> }
>
> For most of the cases, this works well. However, we I tried to read an
> JPEG generated by my Ricoh Caplio digital camera, it failed and emitted
> these message:
>
> ---------- code ----------
> E:/workspace/ruby/idapted/testrmg.rb:6:in `from_blob': JPEG datastream
> contains
> no image `' (Magick::ImageMagickError)
> ....
> -----------------------------
>
> Surprisingly enough, if I use Magick::Image::read method to read the
> same image file directly from harddisk, everything is fine, here is the
> code:
> ---------- code ----------
> g = Magick::Image::read('<local file only>').first
> puts "Width: #{g.columns}; Height: #{g.rows}"
> -----------------------------
>
> Why do Image::read and Image::from_blob make differeces? How to
> determine the geometry of a remote image?
>
> Any comment is appreciated. Thanks!
>
>
>
Under the covers, #read and #from_blob share most of their code. If
Image.read can read the file then Image.from_blob can handle it, too.
The argument to Image.from_blob must be a string containing the entire
image. I'm guessing that the argument you're giving it is only part of
the image. Assign f.read to a variable and display its length. Is it the
same as the size of the image file on disk?


Mike Meng

9/17/2006 3:29:00 AM

0

Thanks to Paul and Timothy.

I've found the problem. I made a stupid mistake when open the URI of an
image file without "b" flag. With "b" flag, everything is ok.

Thanks again.

Mike

Timothy Hunter ??:

> Mike Meng wrote:
> > Hi all,
> > I want to determine the geometry of an image. The image file may be
> > in local harddisk or on web. So I use open-uri and
> > Magick::Image::from_blob to do that work, here is the code:
> >
> > open('<path or URI of image file>') { |f|
> > image = Magick::Image::from_blob(f.read).first
> > puts "Width: #{image.columns}; Height: #{image.rows}"
> > }
> >
> > For most of the cases, this works well. However, we I tried to read an
> > JPEG generated by my Ricoh Caplio digital camera, it failed and emitted
> > these message:
> >
> > ---------- code ----------
> > E:/workspace/ruby/idapted/testrmg.rb:6:in `from_blob': JPEG datastream
> > contains
> > no image `' (Magick::ImageMagickError)
> > ....
> > -----------------------------
> >
> > Surprisingly enough, if I use Magick::Image::read method to read the
> > same image file directly from harddisk, everything is fine, here is the
> > code:
> > ---------- code ----------
> > g = Magick::Image::read('<local file only>').first
> > puts "Width: #{g.columns}; Height: #{g.rows}"
> > -----------------------------
> >
> > Why do Image::read and Image::from_blob make differeces? How to
> > determine the geometry of a remote image?
> >
> > Any comment is appreciated. Thanks!
> >
> >
> >
> Under the covers, #read and #from_blob share most of their code. If
> Image.read can read the file then Image.from_blob can handle it, too.
> The argument to Image.from_blob must be a string containing the entire
> image. I'm guessing that the argument you're giving it is only part of
> the image. Assign f.read to a variable and display its length. Is it the
> same as the size of the image file on disk?

Yi Zheng

9/7/2008 12:23:00 PM

0

Mike Meng wrote:
> Thanks to Paul and Timothy.
>
> I've found the problem. I made a stupid mistake when open the URI of an
> image file without "b" flag. With "b" flag, everything is ok.
>
> Thanks again.
>
> Mike
>
> Timothy Hunter �??�?�?


Hi Mike

I have the similar issue, please check my post:
http://www.ruby-...topic/...

thanks

Yi
--
Posted via http://www.ruby-....