Page 1 of 1

Rmagick hsl problem

Posted: 2009-08-09T08:42:24-07:00
by spacether
I'm having trouble getting
Rmagick's (ruby interface) hsl functions to work for me.

I use the following code:
@canvas is my image object
@canvas.background_color = Magick::Pixel.from_hsla(80, 100, 50, 1)

To try and set a HSLA background color for my image, but it keeps coming
out white.
Any idea why? The image is made okay, no errors are thrown in the ruby
code.

Ruby version: 1.8.6
ImageMagick Version: 6.5.3 Q8
Rmagick Version: rmagick-2.10.0-x86-mswin32
OS: Windows Vista


Full code:

Code: Select all

	require 'rubygems'
  require 'rvg/rvg'
  include Magick
  
class MyImage
def initialize (job_id, width, height)

@job_id = job_id.to_s;
@width = width.to_i;
@height = height.to_i;
@canvas = Magick::Image.new(@width, @height)
#@canvas.colorspace = HSLColorspace
@canvas.background_color = Magick::Pixel.from_hsla(80, 100, 50, 1)
######
#THE ABOVE LINE DOESN'T WORK RIGHT
######
#it will make the pixel but it will not make it the right color
end
def draw ()
# choose random color and put it in a pixel
#@canvas.each_pixel {|pixel, c, r| 
  #ind = rand(5)
  #pixel = $colors[ind]
#}
#@canvas.pixel_color(x, y[, new_color]) -> pixel

end
def finalize (type="gif")
@canvas.write("#{@job_id}.#{type}")
end
end

x = 500
y = 500
increm = 360/5

$colors = Array.new
$colors = [
[0,100,50,1],
[72,100,50,1],
[144,100,50,1],
[216,100,50,1],
[288,100,50,1]
]
# initial array is just the h s l a values
$colors = $colors.map { |xx| Magick::Pixel.from_hsla(xx[0], xx[1], xx[2], x[3]) }  
# convert it to array of pixels
puts $colors[0].class

img = MyImage.new("hsl_test", x, y)
img.draw()
img.finalize('png')