image processing - Color overlay with opacity using ImageMagick in Rails -
we trying apply overlay on series of images before merging them one. right seems imagemagick converting image color applied instead of applying overlay. docs not clear should doing differently. i'd appreciate if have insight on this. code follows:
def self.concatenate_images (source, image) height = fastimage.size(image.url)[0] width = fastimage.size(image.url)[1] source = source.first source = source.resize_to_fill(height, width).quantize(256, magick::graycolorspace).contrast(true) user.color_variant.each_slice(3).with_index |slice,variant_index| slice.each_with_index |color,color_index| colored = magick::image.new(height, width) { self.background_color = color.keys[0]} colored.composite!(source.negate, 0, 0, magick::copyopacitycompositeop) colored.write("#{user.get_img_path}#{color.values[0]}.png") if variant_index == 2 && color_index == 0 system "convert #{user.get_img_path}#{slice[0].values[0]}.png #{image.url} +append #{user.get_img_path}#{slice[0].values[0]}.png" end if color_index!=0 && variant_index != 3 system "convert #{user.get_img_path}#{slice[0].values[0]}.png #{user.get_img_path}#{slice[color_index].values[0]}.png +append #{user.get_img_path}#{slice[0].values[0]}.png" end end end
i don't speak ruby, suspect have wrong blending mode. @ command line, can see available blending modes with:
identify -list compose output
atop blend blur bumpmap changemask clear colorburn colordodge colorize copyblack copyblue copycyan copygreen copy copymagenta copyopacity copyred copyyellow darken darkenintensity dividedst dividesrc dst difference displace dissolve distort dstatop dstin dstout dstover exclusion hardlight hardmix hue in lighten lightenintensity linearburn lineardodge linearlight luminize mathematics minusdst minussrc modulate modulusadd modulussubtract multiply none out overlay on pegtoplight pinlight plus replace saturate screen softlight src srcatop srcin srcout srcover vividlight xor i expect can see similar if in file magick::copyopacitycompositeop defined. so, if take mr bean , magenta rectangle same size:
i can run command this:
convert mrbean.jpg overlay.png -compose blend -composite output.jpg and i'll this:
now, may, or may not want, can run through available blending modes this:
for blend in $(identify -list compose|grep -v blur ); convert -label "$blend" mrbean2.jpg overlay.png -compose $blend -composite miff:- done | montage - -tile 5x result.png which gives shows various results:




Comments
Post a Comment