I’m trying to create a new image using Image::Magick, and set the background color to an RGB value retrieved from a previous step. However, all that is being written out is a black image. I know the RGB values are correct, as I verified those. Below is an example of what I tried.
# Read RGB value at pixel 2,11 in another image
my $swatchImg = new Image::Magick;
$swatchImg->Read($swatchPath)
my @rgb = $swatchImg->GetPixel(x=>2,y=>11);
undef $swatchImg;
# Create a new image, with the background set to the rgb value retrieved above
my $img = Image::Magick->new;
$img->Set(size=>"50x50");
$img->Set(background=>\@rgb);
$img->ReadImage();
I’ve also tried:
$img->Colorize(fill=>\@rgb, opacity=>1);
Any ideas?
Edit:
This worked. Not sure if there is any cleaner approach:
ReadImage("xc:rgb(" . $rgb[0]*100 . "," . $rgb[1]*100 . "," . $rgb[2]*100 . ")")
You can do something like this:
This assumes you are using ImageMagick with q-depth of 16 bits. If only 8 bits, then this:
becomes this:
Although I believe there is a simpler way to just use the decimal values in @rgbdec, perhaps someone will post that.