repairing jpegs

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

repairing jpegs

Post by toshog »

hi all...

just wondering if there is a way to fix jpegs. i'm using a program to open and process images from email attachments. now also using mms to do the same thing. the problem is that the compression that verizon uses is a piece of sh!t. every other carrier's image attachment comes through without a problem but the verizon image is always screwed up. when i try to process it with convert i get:
# convert loo.jpg -normalize -compress None foo.jpg
convert: Not a JPEG file: starts with 0x9d 0xa9 `loo.jpg' @ jpeg.c/EmitMessage/232.
convert: missing an image filename `foo.jpg' @ convert.c/ConvertImageCommand/2775.

the thing is if i open this - loo.jpg - image with photoshop it does open and when i save off psh again to jpeg then convert works fine because photoshop saved it the right way...

so basically is there a way with convert (or any other way) to fix jpegs so that i can process the fixed image with convert...

thanks....
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: repairing jpegs

Post by fmw42 »

try

identify -verbose image.jpg

see if the verbose info confirms it is really a JPEG and not perhaps JP2000 or some other image format for which you do not have the proper delegate library. Or post a link to you image so that the IM folks can confirm if there is really a corruption or some other issue.

Also what IM version are you using?

identify -version

Perhaps you need to upgrade.
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

ok...
here is the output of identify:

$ identify -verbose test01.jpg
identify: Not a JPEG file: starts with 0x9d 0xa9 `test01.jpg' @ jpeg.c/EmitMessage/232.

how do i test for JP2000? what is it?


# identify -version
Version: ImageMagick 6.5.1-1 2010-01-11 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC


these are the headers off the mms message for the attachment image taken using the camera on the phone:

Content-Type: image/jpeg;
name="0212001702.jpg"
Content-ID: <0212001702.jpg>
Content-Location: 0212001702.jpg
Content-Transfer-Encoding: base64


thanks...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: repairing jpegs

Post by fmw42 »

best to post a link to one of your images so the IM folks can examine it and determine what type of image it is.

JP2000 is the uncompressed new jpeg format, but you need the Jasper delegate library for this. I doubt this is the issue. But you can try renaming your file as image.jp2 and see what happens. Also type

convert -list format

and see if it contains JP2 rw-

Perhaps you image is tiff or raw and just has a .jpg suffix? Or it is possible that the header is corrupted and IM does not like that.
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

well.. about the image. i'd have to do that on tuesday when i get a hold of a verizon phone again in the office. the image i have is kinda internal project an i'd have to blur stuff and then is no longer the original from verizon.

the error message "Not a JPEG file: starts with 0x9d 0xa9" is identical for 2 different images taken with different camera phones both on verizon...

i did read about j2000 a bit and it appears that the mime type should be (as you state) image/jp2... but the verizon headers clearly state image/jpeg

from the wiki:
The registered MIME types are defined in RFC 3745. For ISO/IEC 15444-1 it is image/jp2.

the format list is way too long. here is the jpeg part:

JP2* JP2 rw- JPEG-2000 File Format Syntax
JPC* JPC rw- JPEG-2000 Code Stream Syntax
JPEG* JPEG rw- Joint Photographic Experts Group JFIF format (62)
JPG* JPEG rw- Joint Photographic Experts Group JFIF format
JPX* JPX rw- JPEG-2000 File Format Syntax


thanks....
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: repairing jpegs

Post by snibgo »

Does Photoshop report the file is a JPEG?

If the file is a badly-written jpeg, the solution may be to open it and re-save it in a more tolerant program (PS or Gimp). If you need to do this often, you could write a script.
snibgo's IM pages: im.snibgo.com
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

ok. here is an image. was sent over the verizon mms service. apparently i can't attach it here and it wont show up if i put it in the img tags so here is the url and you can get it with wget i guess. or whatever is similar on windows...

http://quereven.com/ca/imgfoo.jpg

convert barfs a it with:

# convert imgfoo.jpg -comress None imgfoo.tif
convert: Not a JPEG file: starts with 0x9d 0xa9 `imgfoo.jpg' @ jpeg.c/EmitMessage/232.
convert: unrecognized option `-comress' @ convert.c/ConvertImageCommand/1055.

i can open it in photoshop.

how can i 'fix' it so image magic can read it?

thanks....
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: repairing jpegs

Post by magick »

The image is not in any format that ImageMagick can recognize.
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

ok. i kinda new that. how can i preprocess it for image magic to recognize it?

all i'm saying is. photoshop can open it. i'm sure verizon is not doing anything that far out of the normal image processing...

thanks...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: repairing jpegs

Post by fmw42 »

I was able to open it in PS and in GraphicConverter, but not in Preview or Debabelizer.

GraphicConverter gave this information about the image:

Image

Strange that is says 32-bits for a jpg?

The EXIF data was as follows:

Make: MSM6500
Model: LSI_S5K4AAFA
Orientation of image: 1
X resolution: 72.0 ppi (pixel per inch)
Y resolution: 72.0 ppi (pixel per inch)
Resolution unit: inch
Software: M6500C-SNAQ-6330
Y and C positioning: centered
-- Exif IFD --:
Exposure time: 1/21 s
Exif version: 0220
Date and time of original data generation: 2010:02:16 20:50:11
Date and time of digital data generation: 2010:02:16 20:50:11
Meaning of each component: YCbCr
Flash: Flash did not fire.
Supported Flashpix version: 0100
Color Space: sRGB
Valid image width in pixel: 960
Valid image height in pixel: 1280
-- Interoperability IFD --:
Interoperability Index: R98
Interoperability Version: 0100
-- End of Interoperability IFD, EXIF IFD continues:
File source: reserved
Scene type: reserved
White balance: Auto white balance
Digital zoom ratio: 1.0
-- Thumbnail IFD --:
Compression scheme: JPEG
X resolution: 72.0 ppi (pixel per inch)
Y resolution: 72.0 ppi (pixel per inch)
Resolution unit: inch
Offset to JPEG SOI: 664
Bytes of JPEG data: 3156



Hope this helps in some way.
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

thanks fmw42...

i guess the question is what do photoshop and the converter know that imagemagick does not...

do you know of any command line utility that would read these images and process them? this whole thing is scripted and the freakin verizon is the only carrier that screws up the images so that they can not be displayed on line...

thanks...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: repairing jpegs

Post by fmw42 »

I know of no tools. I was hoping Magick may see something odd in the data I provided (esp the comment of about 32-bits for a jpeg which is odd to me as jpg does not allow transparency (8bits for each RGB and 8bits transparency is the usual meaning for 32-bits).

If I were you I would complain to verizon and see what they say about the jpeg format they are providing. Perhaps it is just a problem in your cellphone camera? Have you tried any other verizon phone cameras?
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

it's not on my camera. there is this thing i'm doing on line where people can post their images from their phones via mms by sending it to an email address. it works for all the carriers except verizon. i asked a few other people on verizon to do it and they all have the same problem. att, tmobile, sprint work fine with real jpegs.

i figured if photoshop and the converter can open it there must be something in the open source world that can too...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: repairing jpegs

Post by fmw42 »

Photoshop may be very forgiving about the header and open the file even if the header is not correct. Other tools are not so forgiving.

you could write a photoshop script that would open and re-save the image so that perhaps other apps could open it?
toshog
Posts: 23
Joined: 2010-02-12T19:29:43-07:00
Authentication code: 8675308

Re: repairing jpegs

Post by toshog »

yea... that's not going to work. there is no way to put photoshop on a server that has an application to process email attachments. but thanks...
Post Reply