Linux thumbnailer with imagemagick

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
Yuzem

Linux thumbnailer with imagemagick

Post by Yuzem »

Hello
I want to make a thumbnailer for my little application using imagemagick but I am having some problems.

I have it working with nautilus but thunar overwrites them every time.
Comparing my thumbnail with one that does work using "identify -verbose" I found a difference.

The one that works has:
Background Color: white
The one that does not works has:
Background Color: black

How can I set that option?
If I do:
convert input.png -background white output.png
The result is:
Background Color: #00000000

In fact, anything gives me that result with the exception of black.
Is this a bug?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Linux thumbnailer with imagemagick

Post by Bonzo »

I can not help but it would be better if you can post the code you are using with the IM version numbers etc.
Yuzem

Re: Linux thumbnailer with imagemagick

Post by Yuzem »

Code: Select all

convert -version 
Version: ImageMagick 6.2.4 10/02/07 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2005 ImageMagick Studio LLC
The code is simple, I have a png that I want to use as thumbnail:

Code: Select all

convert source.png -background white  destination.png
But it doesn't change it to white.

The complete code:

Code: Select all

	convert  \
		   /usr/local/share/avatar-factory/themes/DVD/$dvd_theme_base.png -geometry  +0+0  -composite \
		   /tmp/thumb$$.png  -geometry  +10+17  -composite \
		   /usr/local/share/avatar-factory/themes/DVD/top.png  -geometry +0+0  -composite \
		   -background white -units Undefined -density 72x72 -depth 8 -set Software "Avatar Factory" -set Thumb::URI "$SOURCE_item_encoded" -set Thumb::MTime "$(stat --format=%Y "$SOURCE_item")" \
		   "$icons_PATH/$icon_NAME.png"
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Linux thumbnailer with imagemagick

Post by anthony »

-background is an override setting for operators. You do not have any operations that use that setting, other than reading and writing an image so it will have little effect.

If you have a image with a transparent area that you want to make white, then flatten the image, whcih will underlay a canvas of the current background color...

Code: Select all

   convert source.png -background white  -flatten destination.png
If background is not set it defaults to the images background meta-data setting if that format supports it (GIF images do, but they are rarely used and usally a incorrect setting). Otherwise it defaults to white.

See IM examples, the rough notes in basics, attributes...
http://imagemagick.org/Usage/basics/#attributes
and on 'flatten', removing background transparency
http://imagemagick.org/Usage/layers/#flatten_bgnd
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Yuzem

Re: Linux thumbnailer with imagemagick

Post by Yuzem »

anthony wrote:If you have a image with a transparent area that you want to make white, then flatten the image, whcih will underlay a canvas of the current background color...

Code: Select all

   convert source.png -background white  -flatten destination.png
Thanks for the answer but I don't want to make white the transparent area.
I want to keep the transparency and change the metadata from:
Background Color: black
to:
Background Color: white

Even using that command and losing the transparency I get:
Background Color: #00000000

That data is available using identify -verbose
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Linux thumbnailer with imagemagick

Post by anthony »

The current -background setting is usally saved with the image.
For GIF it definatally is. But it may not be part of the PNG image file format.

If you can verify that background is a normal PNG meta-data attribute then I suggest you report a bug.

NOTE: before you do, try setting -background before reading the PNG image. typically if a setting like this is set before the image is read or created, then it will become part of the actual images meta-data. Hmmm....

using a test image from IM examples...
identify -verbose wmark_image.png | grep Background
Background color: black
So far so good
convert -background Pink wmark_image.png t.png
identify -verbose t.png | grep Background
Background color: rgb(1,1,1)
I got white.. which is IM normal background color default.
I have no idea why I got white.
convert -background Pink wmark_image.png -taint t.png
identify -verbose t.png | grep Background
Background color: rgb(83.1724%,83.1724%,83.1724%)
Which is a gray color. The -taint flag is meant to mark an image a modified so as to avoid any direct copying of the image via delegates.

From this I would say that PNG background is either undefined, or unset by the IM PNG coder.

Actually like GIF I know of no program that actually makes proper use of the background meta-data of any image. I myself recommend that any program wanting to use a background color, always sets the color that the application actually wants to use and avoid any image supplied setting.

GIF is supposed to use it for its animation disposal method 'background' but all Web browsers, have made this method equivalent to 'set to transparent' rather than 'set to background'. As such it is basically ignored today, though IM does set it right for this format.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Yuzem

Re: Linux thumbnailer with imagemagick

Post by Yuzem »

anthony wrote:The current -background setting is usally saved with the image.
NOTE: before you do, try setting -background before reading the PNG image. typically if a setting like this is set before the image is read or created, then it will become part of the actual images meta-data. Hmmm....
It doesn't work. :(
I got the same result as before.
anthony wrote:
convert -background Pink wmark_image.png t.png
identify -verbose t.png | grep Background
Background color: rgb(1,1,1)
I got white.. which is IM normal background color default.
I have no idea why I got white.
I think rgb(1,1,1) is black. The same result that I got but expressed in a different way.
anthony wrote:
convert -background Pink wmark_image.png -taint t.png
identify -verbose t.png | grep Background
Background color: rgb(83.1724%,83.1724%,83.1724%)
Which is a gray color. The -taint flag is meant to mark an image a modified so as to avoid any direct copying of the image via delegates.
I got:
convert: unrecognized option `-taint'
Must be my imagemagick version (6.2.4) but I need to make it work with that version because it is the version available on the ubuntu repositories.

If I save a png using python the background is always set to white. The problem is that all the custom metadata is deleted and I don't know how to set metadata with python.
With imagemagick I can set the metadata but I can't set the background to white. :? :? :?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Linux thumbnailer with imagemagick

Post by anthony »

Even if we fix the background setting with regards to PNG meta-data saving, it will not be available in version 6.2.4.

What program is requiring the background meta-data to be set correctly?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Yuzem

Re: Linux thumbnailer with imagemagick

Post by Yuzem »

anthony wrote:Even if we fix the background setting with regards to PNG meta-data saving, it will not be available in version 6.2.4.

What program is requiring the background meta-data to be set correctly?
Thunar does, but I am not completly sure if it is because of that.
For some reason thunar overwrites all the thumbnail that my app makes.
Nautilus doesn't do that.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Linux thumbnailer with imagemagick

Post by anthony »

I have looked into thumbnailers under Linux, and there is suposed to be a set of rules that thumbnail generators follow. All I remember is finding it while studying the application "gqview" (which allows you to view a generated 'collection' of images, in my case for image comparisions).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Yuzem

Re: Linux thumbnailer with imagemagick

Post by Yuzem »

Yes I know the rules, here they are:
http://web.archive.org/web/200706222142 ... ation.html

They work with nautilus but not in thunar.
I had finally change the background color with this:

Code: Select all

convert pic.png -depth 16 -background white pic.png
Guess what... the thumbnail still gets overwrited.
I think that the color depth must be 8 for the thumbnail to work and if I set the depth to 8 I can set the background to white.

This thumb doesn't work:

Code: Select all

  Format: PNG (Portable Network Graphics)
  Geometry: 101x128
  Class: DirectClass
  Type: TrueColorMatte
  Endianess: Undefined
  Colorspace: RGB
  Channel depth:
    Red: 16-bits
    Green: 16-bits
    Blue: 16-bits
    Alpha: 16-bits
  Channel statistics:
    Red:
      Min: 0 (0)
      Max: 65535 (1)
      Mean: 22083.9 (0.336979)
      Standard deviation: 22321.1 (0.340597)
    Green:
      Min: 0 (0)
      Max: 65535 (1)
      Mean: 17931.7 (0.27362)
      Standard deviation: 20367.7 (0.310791)
    Blue:
      Min: 0 (0)
      Max: 64688 (0.987076)
      Mean: 15927 (0.243031)
      Standard deviation: 18159.3 (0.277093)
    Alpha:
      Min: 65535 (1)
      Max: 0 (0)
      Mean: 48758.2 (0.744002)
      Standard deviation: 27499.8 (0.41962)
  Alpha: (    0,    0,    0,65535)        #000000000000FFFF
  Colors: 8322
  Rendering-intent: Undefined
  Resolution: 72x72
  Units: Undefined
  Filesize: 53kb
  Interlace: None
  Background Color: white
  Border Color: #DFDFDFDFDFDF0000
  Matte Color: grey74
  Page geometry: 101x128+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Signature: fb50f4d313b7a4513ce7b842452f898c4c5c909a2d932fbd7483275084cd3abf
  Software: GNOME::ThumbnailFactory
  Thumb::MTime: 1200114086
  Thumb::URI: file:///home/azd/Network/300%20(2006).avi
  Tainted: False
  Version: ImageMagick 6.2.4 10/02/07 Q16 http://www.imagemagick.org
And this works:

Code: Select all

  Format: PNG (Portable Network Graphics)
  Geometry: 101x128
  Class: DirectClass
  Type: TrueColorMatte
  Endianess: Undefined
  Colorspace: RGB
  Channel depth:
    Red: 8-bits
    Green: 8-bits
    Blue: 8-bits
    Alpha: 8-bits
  Channel statistics:
    Red:
      Min: 0 (0)
      Max: 255 (1)
      Mean: 85.9068 (0.336889)
      Standard deviation: 87.054 (0.341388)
    Green:
      Min: 0 (0)
      Max: 255 (1)
      Mean: 69.6904 (0.273296)
      Standard deviation: 79.4341 (0.311506)
    Blue:
      Min: 0 (0)
      Max: 252 (0.988235)
      Mean: 61.8628 (0.242599)
      Standard deviation: 70.8115 (0.277692)
    Alpha:
      Min: 255 (1)
      Max: 0 (0)
      Mean: 189.724 (0.744015)
      Standard deviation: 107.005 (0.419629)
  Alpha: (  0,  0,  0,255)        #000000FF
  Colors: 7520
  Rendering-intent: Undefined
  Resolution: 72x72
  Units: Undefined
  Filesize: 23kb
  Interlace: None
  Background Color: white
  Border Color: #DFDFDF00
  Matte Color: grey74
  Page geometry: 101x128+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Signature: ed63c4e3cbc79d9228d2f9c89639a9af1618ba1b6643d2880aba0c50da6eb9de
  Software: GNOME::ThumbnailFactory
  Thumb::MTime: 1200114086
  Thumb::URI: file:///home/azd/Network/300%20(2006).avi
  Tainted: False
  Version: ImageMagick 6.2.4 10/02/07 Q16 http://www.imagemagick.org
The only relevant difference that I see is the channel depth or the background if I set the depth to 8.
Post Reply