lib/chunky_png/canvas/masking.rb
# Creates a new image, based on the current image but with a new theme color.
#
# This method will replace one color in an image with another image. This is done by
# first extracting the pixels with a color close to the original theme color as a mask
# image, changing the color of this mask image and then apply it on the original image.
#
# Mask extraction works best when the theme colored pixels are clearly distinguishable
# from a background color (preferably white). You can set a tolerance level to influence
# the extraction process.
#
# @param [Integer] old_theme_color The original theme color in this image.
# @param [Integer] new_theme_color The color to replace the old theme color with.
# @param [Integer] bg_color The background color on which the theme colored pixels are placed.
# @param [Integer] tolerance The tolerance level to use when extracting the mask image. Five is
#    the default; increase this if the masked image does not extract all the required pixels,
#    decrease it if too many pixels get extracted.
# @return [ChunkyPNG::Canvas] Returns itself, but with the theme colored pixels changed.
# @see #change_theme_color!
# @see #change_mask_color!
Creates a new image, based on the current image but with a new theme color.
This method will replace one color in an image with another image. This is done by
first extracting the pixels with a color close to the original theme color as a mask
image, changing the color of this mask image and then apply it on the original image.

Mask extraction works best when the theme colored pixels are clearly distinguishable
from a background color (preferably white). You can set a tolerance level to influence
the extraction process.
Creates a new image based on the current image but with a new theme color . This method will replace one color in an image with another image . This is done by first extracting the pixels with a color close to the original theme color as a mask image changing the color of this mask image and then apply it on the original image . Mask extraction works best when the theme colored pixels are clearly distinguishable from a background color ( preferably white ) . You can set a tolerance level to influence the extraction process .
def change_theme_color!(old_theme_color, new_theme_color, bg_color = ChunkyPNG::Color::WHITE, tolerance = 5)
        base, mask = extract_mask(old_theme_color, bg_color, tolerance)
        mask.change_mask_color!(new_theme_color)
        replace!(base.compose!(mask))
      end
def change_theme_color! ( old_theme_color , new_theme_color , bg_color = ChunkyPNG :: Color :: WHITE , tolerance = 5 ) base , mask = extract_mask ( old_theme_color , bg_color , tolerance ) mask . change_mask_color! ( new_theme_color ) replace! ( base . compose! ( mask ) ) end
Creates a new image, based on the current image but with a new theme color.
Creates a new image based on the current image but with a new theme color .
Returns itself, but with the theme colored pixels changed.
Returns itself but with the theme colored pixels changed .
ChunkyPNG::Canvas
old_theme_color
<not_specific>
new_theme_color
<not_specific>
bg_color
<not_specific>
tolerance
<not_specific>
<not_specific>
tolerance The tolerance level to use when extracting the mask image. Five is the default; increase this if the masked image does not extract all the required pixels, decrease it if too many pixels get extracted.
tolerance The tolerance level to use when extracting the mask image . Five is the default ; increase this if the masked image does not extract all the required pixels decrease it if too many pixels get extracted .
see
None
see
None