Page 1 of 2

"convert -strip" modifies the image

Posted: 2008-03-23T16:45:18-07:00
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!

Re: "convert -strip" modifies the image

Posted: 2008-03-23T17:13:11-07:00
by magick
We do not anticipate support for lossless transformations from / to JPEG images in ImageMagick anytime soon. Instead use jpegtran as you mentioned.

Re: "convert -strip" modifies the image

Posted: 2011-07-21T05:37:19-07:00
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?

Re: "convert -strip" modifies the image

Posted: 2011-07-21T17:56:39-07:00
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.

Re: "convert -strip" modifies the image

Posted: 2011-07-22T01:21:22-07:00
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

Re: "convert -strip" modifies the image

Posted: 2011-07-22T05:20:34-07:00
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.

Re: "convert -strip" modifies the image

Posted: 2011-07-23T07:26:06-07:00
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?

Re: "convert -strip" modifies the image

Posted: 2011-07-23T09:24:32-07:00
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.

Re: "convert -strip" modifies the image

Posted: 2016-09-12T02:06:23-07:00
by Vanns
what type of metadata -strip removes?

Re: "convert -strip" modifies the image

Posted: 2016-09-12T10:45:59-07:00
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

Re: "convert -strip" modifies the image

Posted: 2016-09-13T22:36:46-07:00
by Vanns
Will it remove copyright information also?

Re: "convert -strip" modifies the image

Posted: 2016-09-13T23:09:13-07:00
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.

Re: "convert -strip" modifies the image

Posted: 2016-09-13T23:38:32-07:00
by Vanns
How to prevent it from doing so? Because I want copyright information after stripping. Is there anyway to do that?

Re: "convert -strip" modifies the image

Posted: 2016-09-14T09:02:20-07:00
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/

Re: "convert -strip" modifies the image

Posted: 2016-09-16T03:26:14-07:00
by Vanns
Can you help with linux syntax?

Thanks