سؤال

All, have been using RMagick/ImageMagick for years with great success. One of the tasks I use it for is on-demand gradient generation (pending full support for CSS gradients, oh god I can't wait).

Recently noticed a bug/behavior that I can't fathom at all. Have been trying to even come up with a theory, thought the bright minds of StackOverflow might be able to help.

In short form, generating gradients as PNGs works fine, unless you're using grayscale values, in which case the output is... strange. Try the below script.

require 'RMagick'
include Magick

puts "ImageMagick version: " + Magick_version
puts "RMagick version: " + Version

fill = GradientFill.new(0, 0, 20, 0, '#888888', '#888888')
img = Image.new(20, 20, fill)
img.write('./test.png') { self.format = 'PNG' }

The expected output would be a 20x20 png that's solid mid-gray. What I get instead is a pure white block. If I have a color for the second value, it seems to work fine. Any ideas?

For reference, I'm using:

ImageMagick version: ImageMagick 6.8.0-2 2012-11-28 Q8
RMagick version: RMagick 2.13.2
هل كانت مفيدة؟

المحلول

As so often happens, 5 minutes after posting this, I found the answer. Short answer, there was a short-lived bug in ImageMagick regarding writing PNGs that are pure gray. Bug was present from 6.8.0-1 to 6.8.0-8.

Upgrading should fix it...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top