I'm trying to make a script for creating halftone dither. Script should take an rgb image and convert it to four png files for all CMYK channels, each being a bitmap with according threshold pattern, as in this image:
So far I made a script for converting image to cmyk, resizing it to wanted size and splitting it by channels. I also found this great resource on making it with ImageMagick - http://www.imagemagick.org/Usage/quantize/#halftone_offset. It seams that it's exactly what I need, but I'm stuck having no idea how to implement this:
convert colorwheel.png -set option:distort:viewport '%wx%h+0+0' \
-colorspace CMYK -separate null: \
\( -size 2x2 xc: \( +clone -negate \) \
+append \( +clone -negate \) -append \) \
-virtual-pixel tile -filter gaussian \
\( +clone -distort SRT 60 \) +swap \
\( +clone -distort SRT 30 \) +swap \
\( +clone -distort SRT 45 \) +swap \
\( +clone -distort SRT 0 \) +swap +delete \
-compose Overlay -layers composite \
-set colorspace CMYK -combine -colorspace RGB \
offset_colorwheel.png
Into what I wrote so far:
require 'rmagick'
include Magick
width = 1181
height = 826
puts "loading"
img = Image.read("123.jpg").first()#.resize_to_fit!(width, height)
puts "converting to cmyk"
img.colorspace = Magick::CMYKColorspace
puts "resizing"
img = img.resize_to_fill(width,height)
puts "channel separation"
a = img.separate(AllChannels)
channels = ["c", "m", "y", "k"]
a.each_with_index do |channel, index|
puts channels[index]
result.write("#{channels[index]}.jpg")
channel.ordered_dither('h4x4a').write("#{channels[index]}.jpg")
end
I would appreciate any suggestions on how to translate given ImageMagick command