# RMagick problem: Image::read works well but Image::from\_blob

**URL:** <https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910>\
**Category:** Ruby\
**Created:** [September 16, 2006, 5:46pm UTC](https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910 "2006-09-16T17:46:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Meng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mike\_Meng](https://www.ruby-forum.com/u/Mike_Meng)\
**Post date:** [September 16, 2006, 5:46pm UTC](https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910/1 "2006-09-16T17:46:45Z")

</div>

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(’’) { |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(’’).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!

---

<div class="post-metadata">

**Author:** ![Mike\_Meng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mike\_Meng](https://www.ruby-forum.com/u/Mike_Meng)\
**Post date:** [September 16, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910/2 "2006-09-16T18:10:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mike\_Meng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mike\_Meng](https://www.ruby-forum.com/u/Mike_Meng)\
**Post date:** [September 16, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910/3 "2006-09-16T18:22:47Z")

</div>

Mike Meng wrote:

> For most of the cases, this works well. However, we I tried to read an  
> Surprisingly enough, if I use Magick::Image::read method to read the  
> 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?

---

<div class="post-metadata">

**Author:** ![Mike\_Meng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mike\_Meng](https://www.ruby-forum.com/u/Mike_Meng)\
**Post date:** [September 17, 2006, 5:31am UTC](https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910/4 "2006-09-17T05:31:25Z")

</div>

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 H. å??é?ï¼?

---

<div class="post-metadata">

**Author:** ![Mike\_Meng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@Mike\_Meng](https://www.ruby-forum.com/u/Mike_Meng)\
**Post date:** [September 7, 2008, 2:28pm UTC](https://www.ruby-forum.com/t/rmagick-problem-image-read-works-well-but-image-from-blob/68910/5 "2008-09-07T14:28:40Z")

</div>

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 H. ï¿½??ï¿½?ï¿½?

Hi Mike

I have the similar issue, please check my post:  
[http://www.ruby-forum.com/topic/164823#new](http://www.ruby-forum.com/topic/164823#new)

thanks

Yi
