Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial 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

SPLITTONE2


Applies a color splittone effect to an image

Download Script

last modified: May 12, 2015



USAGE: splittone2 [-sc shadowcolor] [-sa shadowamt] [-hc highlightcolor] [-ha highlightamt] [-f format] [-t type] [-c compose] [-m mode] [-p] [-b bri] [-c con] infile outfile
USAGE: splittone2 [-help]

-sc ... shadowcolor ...... shadow color; any opaque IM color allowed;
.......................... default=black
-hc ... highlightcolor ... highlight color; any opaque IM color allowed;
.......................... default=white
-sa ... shadowamt ........ shadow amount; 0<=integer<=100; default=30
-ha ... highlightamt ..... highlight amount; 0<=integer<=100; default=30
-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
-m .... mode ............. mode for overlaying the shadow processed image
.......................... with highlight processed image; choices are HS
.......................... (highlight first, then shadow overlaid) or SH
.......................... (shadow first, then high;light overlaid). The
.......................... default=HS.
-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: SPLITTONE2 applies a color splittone effect to an image by adjusting shadow and highlight color separately.

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

-sa shadowamt ... SHADOWAMT is the shadow amount. Values are integers between 0 and 100. The default=30

-ha highlightamt ... HIGHLIGHTAMT is the highlight amount. Values are integers between 0 and 100. The default=30

-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.

-m mode ... MODE specifies the order of shadow and hightlight processing. The choices are: SH (shadow first) or HS (highlight first. The default=SH

-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 Amounts

Arguments:
-sc hsl(61.11%,40%,50%) -sa 100
-hc hsl(4.17%,20%,50%) -ha 100

Arguments:
-sc hsl(61.11%,40%,50%) -sa 50
-hc hsl(4.17%,20%,50%) -ha 100

Arguments:
-sc hsl(61.11%,40%,50%) -sa 100
-hc hsl(4.17%,20%,50%) -ha 50

 

Variation in Format

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

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

 

Variation in Type

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

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

 

Variation in Compose

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

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

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

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

 

Variation in Mode

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

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

 

Variation in Preserve Luminosity

Arguments:
-sc hsl(61.11%,40%,50%) -sa 100
-hc hsl(4.17%,20%,50%) -ha 100

Arguments:
-sc hsl(61.11%,40%,50%) -sa 100
-hc hsl(4.17%,20%,50%) -ha 100
-p

 

Variation in Brightness

Arguments:
-sc hsl(61.11%,40%,50%) -sa 100
-hc hsl(4.17%,20%,50%) -ha 100
-b 0

Arguments:
-sc hsl(61.11%,40%,50%) -sa 100
-hc hsl(4.17%,20%,50%) -ha 100
-b 20



Example 2

Original Image
(source)

 

Variation in Amounts

Arguments:
-sc red -sa 100
-hc yellow -ha 100

Arguments:
-sc red -sa 50
-hc yellow -ha 100

Arguments:
-sc red -sa 100
-hc yellow -ha 50

 

Variation in Format

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-f image

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-f grayscale

 

Variation in Type

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-t color

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-t gradient

 

Variation in Compose

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-c colorize

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-c overlay

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-c softlight

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-c hardlight

 

Variation in Mode

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-m HS

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-m SH

 

Variation in Preserve Luminosity

Arguments:
-sc red -sa 100
-hc yellow -ha 100

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-p

 

Variation in Brightness

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-b 0

Arguments:
-sc red -sa 100
-hc yellow -ha 100
-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
  • Flattens the image, 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 \
    \( $tmpH1 $tmpG1 -alpha off -compose copy_opacity -composite \
    -alpha on -channel A -evaluate multiply $hamtf +channel \) \
    \( $tmpS1 \( $tmpG1 -negate \) -alpha off -compose copy_opacity -composite \
    -alpha on -channel A -evaluate multiply $samtf +channel \) \
    -compose over -flatten $outfile