"convert -strip" modifies the image

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

"convert -strip" modifies the image

Post by naoliv »

Hi!

From http://bugs.debian.org/391982, we saw that when using "convert -strip image.jpg" we get a recompressed image on the end (even if there is nothing to do).

It would be good if this process could modify the images losslessly, like jpegtran can do ("jpegtran -copy none image.jpg > newimage.jpg" won't recompress the JPEG)

Thank you!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "convert -strip" modifies the image

Post by magick »

We do not anticipate support for lossless transformations from / to JPEG images in ImageMagick anytime soon. Instead use jpegtran as you mentioned.
jverne
Posts: 11
Joined: 2011-07-21T05:26:15-07:00
Authentication code: 8675308

Re: "convert -strip" modifies the image

Post by jverne »

Hi magick,

I saw this interesting study done by Stoyan Stefanov showing that jpeg images compressed by imagemagick are 2% smaller on average than performing the same operation with jpegtran, cf.:

http://www.yuiblog.com/blog/2008/12/05/imageopt-4/

Is this due to imagemagick's slightly lossy conversion? Or it is because imagemagick's compression of jpeg images is better than jpegtran's compression?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: "convert -strip" modifies the image

Post by anthony »

IM just uses the JPEG library, same as most other Image Processing Packages.

Any reducing in size is probably due to IM not adding more meta-data to the image! Something that other packages seems to like to do, so as to store its own special meta-data actions. Photoshop especially likes to store resolution information in its own profile additions, where IM prefers to use the standard resolution meta-data location.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jverne
Posts: 11
Joined: 2011-07-21T05:26:15-07:00
Authentication code: 8675308

Re: "convert -strip" modifies the image

Post by jverne »

Hi anthony,

the study was done stripping all meta-data because it says that the following commands were run:

> jpegtran -copy none -optimize source.jpg result.jpg
> jpegtran -copy none -progressive source.jpg result.jpg

Either IM strips meta-data even better or compress data even better. Either way it would be a nice addition having it losslessly. :D
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: "convert -strip" modifies the image

Post by glennrp »

The differences are due to the recompression and not due to metadata.
The IM JPEG decoder estimates the "quality" used to compress the original
image. If the original image was created with IJG software then the estimate
is exact, but if it came from a camera using proprietary quantization tables,
it won't be an exact match, and IM recompresses the image using
quantization tables that best correspond to the estimated quality. This is usually the case.
jverne
Posts: 11
Joined: 2011-07-21T05:26:15-07:00
Authentication code: 8675308

Re: "convert -strip" modifies the image

Post by jverne »

Hi glennrp,

Thanks for the explanation.

I have one further question:

Let us suppose that the quantization tables are the same. After decompression, do IM uses the same algorithm as jpegtran to (re)compress image's data or IM algorithm is more powerful and that also contributes to the 2% difference?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: "convert -strip" modifies the image

Post by glennrp »

I think jpegtran is part of the IJG distribution and uses the same code for decompressing.

It's simple enough to test: compress a file with IM and then copy it with jpegtran:
  • [glennrp@studio ~]$ convert logo: -resize 200% logo2x.jpg
    [glennrp@studio ~]$ jpegtran logo2x.jpg > logo2xjt.jpg
    [glennrp@studio ~]$ convert logo2xjt.jpg logo2xjtim.jpg
    [glennrp@studio ~]$ jpegtran logo2xjtim.jpg > logo2xjtimjt.jpg
    [glennrp@studio ~]$ ls -l logo2x*
    -rw-rw-r-- 1 glennrp glennrp 95601 Jul 23 12:16 logo2x.jpg
    -rw-rw-r-- 1 glennrp glennrp 101152 Jul 23 12:17 logo2xjt.jpg
    -rw-rw-r-- 1 glennrp glennrp 92011 Jul 23 12:17 logo2xjtim.jpg
    -rw-rw-r-- 1 glennrp glennrp 100558 Jul 23 12:21 logo2xjtimjt.jpg
    [glennrp@studio ~]$
Well, that's interesting. jpegtran actually made it bigger,
repeatedly.

I verified with "identify -verbose" that jpegtran dies not change
the image signature, so there is no lossy transformation happening.
"convert" does change the signature.
Vanns
Posts: 11
Joined: 2016-08-29T05:28:51-07:00
Authentication code: 1151

Re: "convert -strip" modifies the image

Post by Vanns »

what type of metadata -strip removes?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "convert -strip" modifies the image

Post by fmw42 »

Vanns wrote:what type of metadata -strip removes?
Pretty much all non-pixel data including EXIF, clip paths, TIFF tags and profiles.

See also http://www.imagemagick.org/script/comma ... .php#strip
Vanns
Posts: 11
Joined: 2016-08-29T05:28:51-07:00
Authentication code: 1151

Re: "convert -strip" modifies the image

Post by Vanns »

Will it remove copyright information also?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "convert -strip" modifies the image

Post by fmw42 »

Yes, I believe so, if it is in a meta-data field, but not if the copyright is imbedded in the image pixel data.
Vanns
Posts: 11
Joined: 2016-08-29T05:28:51-07:00
Authentication code: 1151

Re: "convert -strip" modifies the image

Post by Vanns »

How to prevent it from doing so? Because I want copyright information after stripping. Is there anyway to do that?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "convert -strip" modifies the image

Post by fmw42 »

Copy the information before stripping and then put it back afterwards.

You can extract data such as copyright from your file and put it into a string variable using string formats

Unix syntax:

Code: Select all

copyrightinfo=$(convert yourimage -format "%[copyright]" info:)

Code: Select all

convert yourimage -strip <some processing> -set copyright "$copyrightinfo" yourresult
See

http://www.imagemagick.org/script/escape.php
http://www.imagemagick.org/Usage/windows/
Vanns
Posts: 11
Joined: 2016-08-29T05:28:51-07:00
Authentication code: 1151

Re: "convert -strip" modifies the image

Post by Vanns »

Can you help with linux syntax?

Thanks
Post Reply