Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

SPLITTONE3


Applies a color splittone effect to an image

Download Script

last modified: December 15, 2018



USAGE: splittone3 [-sc shadowcolor] [-hc highlightcolor] [-m mix] [-f format] [-t type] [-c compose] [-p] [-b bri] [-c con] infile outfile
USAGE: splittone3 [-help]

-sc ... shadowcolor ...... shadow color; any opaque IM color allowed;
.......................... default=black
-hc ... highlightcolor ... highlight color; any opaque IM color allowed;
.......................... default=white
-m .... mix .............. mix between shadow and highlight coloring;
.......................... 0<=interger<=100; 0 is all shadow coloring;
.......................... 100 is all highlight coloring; default=50
-f .... format ........... format of image to process; image or grayscale;
.......................... default=image
-t .... type ............. type of color processing; color or gradient;
.......................... default=color
-c .... compose .......... compose method to use; choices are: colorize,
.......................... overlay, softlight and hardlight; default=colorize
-p ....................... preserve luminosity
-b .... bri .............. brightness; -100<integer<100; default=0
-s .... sat .............. saturation; -100<integer<100; default=0

PURPOSE: To apply a color splittone effect to an image.

DESCRIPTION: SPLITTONE3 applies a color splittone effect to an image by blending shadow and highlight color.

ARGUMENTS:

-sc shadowcolor ... SHADOWCOLOR is the shadow color. Any opaque IM color is allowed. The default=black

-hc highlightcolor ... HIGHLIGHTCOLOR is the highlight color. Any opaque IM color is allowed. The default=black

-m mix ... MIX between shadow and highlight coloring. Values are integers between 0 and 100. Zero is all shadow coloring. One hundred is all highlight coloring. The default=50 (equal blend).

-f format ... FORMAT the image to process. Choices are: image (leave image unchanged) or grayscale (convert image to grayscale before processing). The default=image.

-t type ... TYPE of color processing. The choices are: color (solid color composition of grayscale version with image) or gradient (+level-colors composition of grayscale version with image). The default=color.

-c compose ... COMPOSE method to use to combine the image and the colored grayscale image. The choices are: colorize, overlay, softlight and hardlight. The default=colorize.

-p ... Preserve luminosity.

-b bri ... BRI is the percent change in brightness. Values are integers between -100 and 100. The default=0 (no change)

-s sat ... SAT is the percent change in saturation. Values are integers between -100 and 100. The default=0 (no change)

LIMITATION: Works best for compose=colorize when using IM 6.8.5.5 or higher due to the introduction and use of colorspace HCLp. Otherwise, a quite different result will be obtained using colorspace HSL.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Example 1

Original Image
(source)

 

Variation in Mix

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 25

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 75

 

Variation in Format

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -f image

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -f grayscale

 

Variation in Type

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -t color

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -t gradient

 

Variation in Compose

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c colorize

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c overlay

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c softlight

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c hardlight

 

Variation in Preserve Luminosity

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c colorize

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c colorize -p

 

Variation in Brightness

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c colorize -b 0

Arguments:
-sc hsl(61.11%,40%,50%)
-hc hsl(4.17%,20%,50%)
-m 50 -c colorize -b 20



Example 2

Original Image
(source)

 

Variation in Amounts

Arguments:
-sc red -hc yellow
-m 50

Arguments:
-sc red -hc yellow
-m 25

Arguments:
-sc red -hc yellow
-m 75

 

Variation in Format

Arguments:
-sc red -hc yellow
-m 50 -f image

Arguments:
-sc red -hc yellow
-m 50 -f grayscale

 

Variation in Type

Arguments:
-sc red -hc yellow
-m 50 -t color

Arguments:
-sc red -hc yellow
-m 50 -t gradient

 

Variation in Compose

Arguments:
-sc red -hc yellow
-m 50 -c colorize

Arguments:
-sc red -hc yellow
-m 50 -c overlay

Arguments:
-sc red -hc yellow
-m 50 -c softlight

Arguments:
-sc red -hc yellow
-m 50 -c hardlight

 

Variation in Preserve Luminosity

Arguments:
-sc red -hc yellow
-m 50 -c colorize

Arguments:
-sc red -hc yellow
-m 50 -c colorize -p

 

Variation in Brightness

Arguments:
-sc red -hc yellow
-m 50 -c colorize -b 0

Arguments:
-sc red -hc yellow
-m 50 -c colorize -b 20



What the script does is as follows for the default case, but with user specified colors:

  • Creates a grayscale version of the image
  • Creates solid color image for each of the shadow color and highlight color
  • Uses -compose colorize to apply color to the grayscale image for each case
    of shadows and highlights
  • Puts the grayscale image into the alpha channel of the colorized shadow
    and highlight images
  • Blends the highlight colored image and the shadow colored image

This is equivalent to the following IM commands:

  • sproc="-fill $scolor -colorize 100%"
  • hproc="-fill $hcolor -colorize 100%"
  • samtf=`convert xc: -format "%[fx:$samt/100]" info:`
  • hamtf=`convert xc: -format "%[fx:$hamt/100]" info:`
  • convert $infile -colorspace gray -auto-level $tmpG1
  • convert $tmpG1 \
    \( -clone 0 $sproc -colorspace HCLp -separate +channel \) \
    \( -clone 0 -colorspace HCLp -channel b -separate +channel \) \
    -delete 0,3 -set colorspace HCLp -combine -colorspace sRGB $tmpS1
  • convert $tmpG1 \
    \( -clone 0 $hproc -colorspace HCLp -separate +channel \) \
    \( -clone 0 -colorspace HCLp -channel b -separate +channel \) \
    -delete 0,3 -set colorspace HCLp -combine -colorspace sRGB $tmpH1
  • convert $infile \
    \( $tmpS1 \( $tmpG1 -blur 0x$blur -negate -auto-level \) \
    -alpha off -compose copy_opacity -composite \) \
    -compose over -flatten $tmpS1
  • convert $infile \
    \( $tmpH1 \( $tmpG1 -blur 0x$blur -auto-level \) \
    -alpha off -compose copy_opacity -composite \) \
    -compose over -flatten $tmpH1
  • convert \( $tmpS1 \) \( $tmpH1 \) \
    -define compose:args=$mix -compose blend -composite -modulate 100,$sat,100 $outfile