ImageMagick: Properly set alpha channel values for XCF Thumbnail
Closed, ResolvedPublic

Description

This is an upstream bug. I'm just marking it here so people who are interested can keep track of it.

Compare the following two images:

https://commons.wikimedia.org/wiki/File:%22What_a_Brilliant_Idea!%22_Barnstar.png

https://commons.wikimedia.org/wiki/File:%22What_a_Brilliant_Idea!%22_Barnstar.xcf

The first is very close to the PNG that Gimp produces from the XCF file. Thumbnails on the XCF file page should look like the PNG upload's file page.


Version: unspecified
Severity: enhancement

bzimport set Reference to bz35622.
MarkAHershberger created this task.Via LegacyMar 30 2012, 8:42 PM
Bawolff added a comment.Via ConduitMar 31 2012, 1:22 AM

Created attachment 10353
short gimp script to open an xcf file, merge visible layers, resize, save as a png

I think over the long term we should look at using gimp directly. xcf is gimps internal format, and as such its really complicated, so its not surprising that image magick only has cursory support for it. After all imagemagick is more concerned with manipulating formats link png, jpg, etc that are meant for general use.

Gimp can be used to scale images with the following command (not sure how efficient this is. Yes I know the command line is scary)

gimp -d -i -b '( (lambda ( filename width height ) (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image))) (finalfilename (string-append filename ".png")))(gimp-image-merge-visible-layers image CLIP-TO-IMAGE)(set! drawable (car (gimp-image-get-active-layer image)))(gimp-image-scale-full image width height INTERPOLATION-CUBIC)(gimp-file-save RUN-NONINTERACTIVE image drawable finalfilename finalfilename)(gimp-image-delete image))) "/path/to/image.xcf" 320 240 ) (gimp-quit 0)' > /dev/null

Which would scale the /path/to/image.xcf to 320x240 pixels (The filename, width and height come at end).

I'm attaching a scheme file version of the above command with better spacing. Its possible to have it in a separate file and avoid the insane command line, but i think that's probably not ideal for mediawiki's use case. Anyhow see the docs at http://www.gimp.org/tutorials/Basic_Batch/

Attached: gimp-resize.scm

MarkAHershberger added a comment.Via ConduitApr 1 2012, 4:51 PM

Looks like the ImageMagick peeps have a patch!
w00!

http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20642#p82784

TheDJ added a comment.Via ConduitApr 1 2012, 5:17 PM

Awesome, good work on reaching out Mark !

TheDJ added a comment.Via ConduitApr 27 2012, 12:29 PM

"I can confirm that that specific XCF file is now 'flattening' correctly.

Just be sure that you do not set a global -compose setting before the -flatten operation, as this will likely override individual layer image compose settings."

Seems fixed upstream.

McZusatz added a comment.Via ConduitJun 13 2012, 11:26 AM

(In reply to comment #3)

Looks like the ImageMagick peeps have a patch!
w00!

http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20642#p82784

Thanks. How long does it usually take until the changes get visible on commons?

Reedy added a comment.Via ConduitJun 13 2012, 11:28 AM

(In reply to comment #6)

(In reply to comment #3)
> Looks like the ImageMagick peeps have a patch!
> w00!
>
> http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20642#p82784

Thanks. How long does it usually take until the changes get visible on commons?

imagemagick needs rebuilding and pushing. Depending on when this made it into the ubuntu apt repositories, it may mean that with the upgrade of the image scalers to 12.04, the benefit will come in

Reedy added a comment.Via ConduitJun 13 2012, 11:32 AM

We look to repackage this ourselves, so I'm not sure if we'll go to the default package..

Currently:
reedy@srv219:~$ convert --version
Version: ImageMagick 6.6.2-6 2011-03-09 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features:

http://packages.ubuntu.com/search?keywords=imagemagick&searchon=names&suite=lucid&section=all

lucid (graphics): image manipulation programs
7:6.5.7.8-1ubuntu1.2 [security]: amd64 i386

http://packages.ubuntu.com/search?keywords=imagemagick&searchon=names&suite=precise&section=all

precise (graphics): image manipulation programs
8:6.6.9.7-5ubuntu3.1 [security]: amd64 i386

Bawolff added a comment.Via ConduitJul 4 2014, 3:42 AM

(In reply to Marco from comment #9)

imagemagick seems to have problems with indexed .xcf files. See this thumb:
https://upload.wikimedia.org/wikipedia/commons/thumb/archive/4/40/
20120923105304!Crimea-no.xcf/120px-Crimea-no.xcf.png (thumb of
https://commons.wikimedia.org/wiki/File:Crimea-no.xcf )

Looks like it doesn't support them at all. In gerrit change https://gerrit.wikimedia.org/r/#/c/144115/ I told MW to just give up on indexed files, and display a generic icon on the file description page ([[File:Xcf.png]] as of https://gerrit.wikimedia.org/r/#/c/144116/ )

gerritbot added a comment.Via ConduitJul 4 2014, 5:04 AM

Change 144118 had a related patch set uploaded by Brian Wolff:
Fix alpha transparency in XCF images

https://gerrit.wikimedia.org/r/144118

Bawolff added a comment.Via ConduitJul 4 2014, 5:08 AM

(In reply to Gerrit Notification Bot from comment #11)

Change 144118 had a related patch set uploaded by Brian Wolff:
Fix alpha transparency in XCF images

https://gerrit.wikimedia.org/r/144118

This was in the title of the bug, but alpha channel isn't mentioned elsewhere in this bug. (Although image magick developers do mention it at http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20642#p82834 , which I only discovered after I figured it out for myself).

I'm unclear what else is to be done for this bug. Most of this is an upstream issue (e.g. Indexed xcf file support is going to depend on image magick implementing that). It might be a cool enhancement request to allow gimp rendering of xcf files, for third parties, even if WMF doesn't want to use that.

So to be clear, can someone summarize if there is more to be done here?

gerritbot added a comment.Via ConduitJul 8 2014, 2:40 PM

Change 144118 merged by jenkins-bot:
Fix alpha transparency in XCF images

https://gerrit.wikimedia.org/r/144118

McZusatz added a comment.Via ConduitJul 20 2014, 10:47 AM

(In reply to Bawolff (Brian Wolff) from comment #12)

So to be clear, can someone summarize if there is more to be done here?

I don't think so, as you already uploaded all patches. Though, we need to wait for bug 63899 (ubuntu-trusty) to be fixed.

Bawolff added a comment.Via ConduitJul 20 2014, 2:33 PM

Hmm. newer image magick doesn't seem to like having the -thumbnail widthxheight! line before the layer merge part. Seem to interpret that as make all the layers precisely widthxheight.

gerritbot added a comment.Via ConduitJul 20 2014, 2:51 PM

Change 147909 had a related patch set uploaded by Brian Wolff:
For xcf files, compose layers before scaling

https://gerrit.wikimedia.org/r/147909

gerritbot added a comment.Via ConduitJul 21 2014, 12:30 PM

Change 147909 merged by jenkins-bot:
For xcf files, compose layers before scaling

https://gerrit.wikimedia.org/r/147909

tomasz added a comment.Via ConduitAug 5 2014, 8:02 PM

Both patches have been merged, assuming bug is fixed.

Gilles added a project: Multimedia.Via WebDec 4 2014, 10:52 AM
Gilles moved this task to Closed on the Multimedia workboard.Via WebDec 4 2014, 10:54 AM
Steinsplitter added a subscriber: Steinsplitter.Via WebMay 17 2015, 8:06 AM

https://commons.wikimedia.org/w/index.php?title=Template:XCF:

Warning sign Warning: XCF rendering is currently under development and thumbnails could contain errors.

Can we remove this warning from the template? It is fixed now?

McZusatz added a comment.Via WebMay 17 2015, 9:09 PM

No, the upstream fix ( http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20642#p82834 ) implies we can do better on the test case mentioned in comment #1 ( https://commons.wikimedia.org/wiki/File:%22What_a_Brilliant_Idea!%22_Barnstar.xcf )

This is tracked in the blocking task T65899, though.

Bawolff added a comment.Via WebMay 18 2015, 5:19 AM

Although the image magick upgrade may help significantly, it should be noted that we will probably never be exactly as good as the gimp, unless we change to using the gimp directly. Whether or not we're "good enough" to remove the warning on the template is a call for commons to make (imo)

Add Comment