Forum: Ruby Help! JPEG marker not found!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Min j. (Guest)
on 2008-10-17 13:33
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!
Lars C. (Guest)
on 2008-10-17 14:01
(Received via mailing list)
On Oct 17, 11:32 am, Min jm <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}
Min j. (Guest)
on 2008-10-17 15:47
It works perfectly now!! Thanks so much!
This topic is locked and can not be replied to.