"convert" produces larger files than GIMP?

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?".
Post Reply
User avatar
jasmine
Posts: 4
Joined: 2018-07-12T07:21:39-07:00
Authentication code: 1152

"convert" produces larger files than GIMP?

Post by jasmine » 2018-07-12T07:36:21-07:00

Dear all =)

When I remove white border and scale it down to 1000 pixels in height with "convert" the output is almost not smaller then the original. If I do the same with GIMP, if gets a lot smaller. Here are the results:

Code: Select all

 1089154 Jun 28 10:34 01005/figs/16/plotFigPureCurve01.png
  962120 Jul 12 16:12 01005/figs/16/plotFigPureCurve01_trim_cut.png
  770324 Jul 12 16:13 01005/figs/16/plotFigPureCurve01_trim_gimp.png
 1040069 Jul 12 16:09 01005/figs/16/plotFigPureCurve01_trim.png
The commands I use are

Code: Select all

convert plotFigPureCurve01.png -border 1x1 -fuzz 15% -trim plotFigPureCurve01_trim.png
convert plotFigPureCurve01_trim.png -resize x1000 -define png:compression-level=9 plotFigPureCurve01_trim_cut.png
gimp plotFigPureCurve01_trim.png
And the image is the below.

Question

Can anyone see how I can get "convert" to produce just as small files as GIMP?

The image is this https://ibb.co/dNtJNT

Hugs,
Jasmine =)

Image
Last edited by jasmine on 2018-07-13T02:11:18-07:00, edited 1 time in total.

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

Re: "convert" produces larger files than GIMP?

Post by snibgo » 2018-07-12T07:57:29-07:00

I'm unclear what image you have saved using both Gimp and IM, that you are comparing the sizes of.

IM has a number of options for PNG compression, but no particular setting will always give the maximum compression.

For that, I use an external tool: pngcrush.

You might be able to analyze the Gimp image, to see what settings have been used, and use those in IM.
snibgo's IM pages: im.snibgo.com

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

Re: "convert" produces larger files than GIMP?

Post by fmw42 » 2018-07-12T09:27:47-07:00

If you start with an 8-bit total color image and resize it, you will introduce new colors so that you end up with 24-bit color. This increases the file size. You need to convert the result back to 8-bit color.

Try

Code: Select all

convert image.png -resize ... PNG8:result.png

User avatar
jasmine
Posts: 4
Joined: 2018-07-12T07:21:39-07:00
Authentication code: 1152

Re: "convert" produces larger files than GIMP?

Post by jasmine » 2018-07-13T05:05:25-07:00

Very interesting posts! I have now pngcrushed all images and checked, and the original is 24bit already.

Below is the result. The gimp cropped image is still much smaller. The IM version have "2063x2063+621+603". Does that mean I haven't really cropped the image despite it looks like I have?

Code: Select all

/tmp$ ll plotFigPureCurve01_trim*
-rw-rw-r-- 1 jasm jasm 764960 Jul 13 13:57 plotFigPureCurve01_trim_gimp.png
-rw-rw-r-- 1 jasm jasm 953850 Jul 13 13:57 plotFigPureCurve01_trim_im.png
-rw-rw-r-- 1 jasm jasm 974869 Jul 13 13:57 plotFigPureCurve01_trim.png
/tmp$ identify plotFigPureCurve01_trim*
plotFigPureCurve01_trim_gimp.png PNG 822x1000       822x1000+0+0 8-bit sRGB 764960B 0.000u 0:00.000
plotFigPureCurve01_trim_im.png   PNG 822x1000  2063x2063+621+603 8-bit sRGB 953850B 0.000u 0:00.000
plotFigPureCurve01_trim.png      PNG 1196x1455 3002x3002+903+878 8-bit sRGB 974869B 0.000u 0:00.000
/tmp$
The one at the bottom is the original before it have been cropped by either IM or GIMP.

246246
Posts: 157
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: "convert" produces larger files than GIMP?

Post by 246246 » 2018-07-13T07:45:44-07:00

jasmine wrote:
2018-07-13T05:05:25-07:00
Below is the result. The gimp cropped image is still much smaller. The IM version have "2063x2063+621+603". Does that mean I haven't really cropped the image despite it looks like I have?
No, it is cropped. If you want 822x1000+0+0 in identify output, add +repage to your command.

I guess the output from IM and gimp is not identical. If the following command

Code: Select all

compare -format '%c\n' -metric MSE plotFigPureCurve01_trim_gimp.png plotFigPureCurve01_trim_im.png NUL
returns other than '0 (0)', it means they are different. I guess you use 'image -> scale image' dialog with the default Cubic setting in Gimp, that use different method for resizing image. So try -scale instead of -resize in IM command. It will generate closer size file to gimp.

See https://www.imagemagick.org/Usage/resize/#other

User avatar
jasmine
Posts: 4
Joined: 2018-07-12T07:21:39-07:00
Authentication code: 1152

Re: "convert" produces larger files than GIMP?

Post by jasmine » 2018-07-16T03:10:56-07:00

"compare" gave "75.6471 (0.0011543)" and with "-scale" it is comparable to GIMP.

Thanks a lot for all the help =)

Post Reply