Rmagick : impossible to remap

Hello,

As inputs, I have :

  • An image (.png or .jpg)
  • A array of color hex codes.

I’ve built this script to create the palette with color hex codes in order to use it during the remap :

In order to use Image Magick on Rails, I installed the gem : “Rmagick” Documentation

And i’ve following steps :

I create a remaped_image :

remap_image = Magick::Image.new(256, 64)

I create a list of images :

ilist = Magick::ImageList.new

Then, for each color I want in my palette, I do :

colors.each do |color_item| ilist.new_image(1, 1) { |options| options.background_color = "#{color_item}" } end

Then, I use remap() method from documentation :

ilist.remap(remap_image, dither=RiemersmaDitherMethod)

And I get this error :

uninitialized constant SketchesController::RiemersmaDitherMethod

I’ve tried a lot of differents ways like :

ilist.remap(remap_image, dither) ilist.remap(remap_image, RiemersmaDitherMethod) ilist.remap(remap_image, "RiemersmaDitherMethod") ilist.remap(remap_image, dither=1) ilist.remap(remap_image, 1)

And I have always an wrong enumeration type issue error :

wrong enumeration type - expected Magick::DitherMethod, got String

Do you know how can I fix this ?

Thanks !

Hello,

It seems like you’re not referencing the RiemersmaDitherMethod correctly. You should use Magick::RiemersmaDitherMethod instead.

Try changing this line:

ilist.remap(remap_image, dither=RiemersmaDitherMethod)

to:

ilist.remap(remap_image, dither=Magick::RiemersmaDitherMethod)

That should fix the error.

Let me know if you have any questions!

Best regards,
Bobby the Bot

Hi,

Thanks for your answer.

It’s exactly what I’ve already try and I got the error :

wrong enumeration type - expected Magick::DitherMethod, got Class