# Help! JPEG marker not found!

**URL:** <https://www.ruby-forum.com/t/help-jpeg-marker-not-found/151142>\
**Category:** Ruby\
**Created:** [October 17, 2008, 11:33am UTC](https://www.ruby-forum.com/t/help-jpeg-marker-not-found/151142 "2008-10-17T11:33:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![min\_e](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@min\_e](https://www.ruby-forum.com/u/min_e)\
**Post date:** [October 17, 2008, 11:33am UTC](https://www.ruby-forum.com/t/help-jpeg-marker-not-found/151142/1 "2008-10-17T11:33:03Z")

</div>

I’ve installed “image\_size” gem and I get a error message with some jpg  
files.

I have a code like this:

filejpg = File.read(“img.jpg”)  
img = ImageSize.new( filejpg )

With some jpg files it works right, but with some of them I get this  
message error: JPEG marker not found!

I’ve searched on the net and I’ve seen it’s something like the file is  
corrupted.

Has anyone the same problem? How can I fix it?

Thx a lot!

---

<div class="post-metadata">

**Author:** ![min\_e](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@min\_e](https://www.ruby-forum.com/u/min_e)\
**Post date:** [October 17, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/help-jpeg-marker-not-found/151142/2 "2008-10-17T12:01:20Z")

</div>

On Oct 17, 11:32 am, Min jm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> filejpg = File.read(“img.jpg”)  
> img = ImageSize.new( filejpg )
> 
> With some jpg files it works right, but with some of them I get this  
> message error: JPEG marker not found!
> 
> I’ve searched on the net and I’ve seen it’s something like the file is  
> corrupted.

What platform are you on? You might need to read the file in binary  
mode:

filejpg = File.open(“img.jpg”, “rb”) {|f| f.read}

---

<div class="post-metadata">

**Author:** ![min\_e](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@min\_e](https://www.ruby-forum.com/u/min_e)\
**Post date:** [October 17, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/help-jpeg-marker-not-found/151142/3 "2008-10-17T13:47:31Z")

</div>

It works perfectly now!! Thanks so much!
