Page MenuHomePhabricator

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

Details

Reference
bz35622

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 12:15 AM
bzimport set Reference to bz35622.

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:

Awesome, good work on reaching out Mark !

"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.

(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?

(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

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

(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/ )

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

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

(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?

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

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

(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.

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.

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

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

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

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

Both patches have been merged, assuming bug is fixed.

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?

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.

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)

Restricted Application added a subscriber: Matanya. · View Herald Transcript