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.

SPOTS


Converts the image into a series of uniform-colored spots.

Download Script

last modified: December 15, 2018



USAGE: spots [-s size] [-t type] [-p pad] [-b bgcolor] [-e edge] [-E ecolor] [-B brightness] [-C Contrast] infile [spotfile] outfile
USAGE: spots [-help]

-s .... size .......... spot size expressed as WxH in pixels; default=5x5
-t .... type .......... type of spot shape; choices are: circle (or c),
....................... square (or s), or diamond (or d); default=circle
-p .... pad ........... padding or border around spot cell in pixels on
....................... each side; integer>=0; default=1
-b .... bgcolor ....... background color to apply to image where spot
....................... does not cover; any valid IM color; default=black
-e .... edge .......... edge thickness accent around spot shape;
....................... integer>=0; default=0
-E .... ecolor ........ color of accent edge around spot shape;
....................... any valid IM color; default=gray
-B .... brightness .... percent change in brightness of spots;
....................... integer; default=0
-C .... contrast ...... percent change in contrast of spots;
....................... integer; default=0

PURPOSE: Converts the image into a series of uniform-colored spots.

DESCRIPTION: SPOTS converts the image into a series of uniform-colored spots. The shape of spots allowed are: circle (ellipse), square (rectangle) or diamond. The spot size may be adjusted. A colored edge may also be placed around each spot. An optional spotfile may be provided to define some other shape than those built-in.

ARGUMENTS:

-s size ... SIZE is the WxH dimensions of the spot cell. Values are a pair of positive integers separated by an x. The default=5x5. If only one value is provided, it will be used for both. This parameter is ignored if a spotfile is provided.

-t type ... TYPE is the type of spot shape. The choices are: circle (or c), square (or s), diamond (or d). These may be asymmetric as ellipses or rectangles as controlled by the size parameters. This parameter is ignored if a spotfile is provided.

-p pad ... PAD is the border around the spot cell. Values are integers>=0. The default=1.

-b bgcolor ... BGCOLOR is the color to apply to the image between the spots. Any valid IM color is allowed. The default=black.

-e edge ... EDGE is the thickness of the optional edge hightlight around the spot shape. Values are integers>=0. The default=0.

-E ecolor ... ECOLOR is the color of the edge highlight. Any valid IM color is allowed. The default=gray.

-B brightness ... BRIGHTNESS is the percent change in brightness of the spot colors. Values are integers. The default=0

-C contrast ... CONTRAST is the percent change in contrast of the spot colors. Values are integers. The default=0

The spotfile must be a binary mask with white for the shape and black for the background and no alpha channel.

REQUIREMENTS: IM 6.3.6-1 or higher due to the use of -define distort:viewport=WxH+X+Y with -distort SRT.

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


Original Image
( http://www.thecartoonpictures.com/r-cartoon-animal-224-cartoon-parrot-1465.htm)

 

Arguments:
-s 5x5 -t circle

 

Arguments:
-s 5x10 -t circle

 

Arguments:
-s 10x5 -t circle

 

Arguments:
-s 10x10 -t circle

 

Arguments:
-s 5x5 -t square

 

Arguments:
-s 7x7 -t diamond


Original Image

 

Arguments:
-s 5x5 -t circle -B 20 -C 20

 

Arguments:
-s 10x10 -t circle -B 20 -C 20

 

Arguments:
-s 15x15 -t circle -B 20 -C 20

 

Arguments:
-s 15x15 -t circle -B 20 -C 20 -e 1 -E gray

 

Arguments:
-s 15x15 -t diamond -B 20 -C 20

 

Arguments:
-s 15x15 -t diamond -B 20 -C 20 -e 1 -E gray

 

Arguments:
-s 15x15 -t square -B 20 -C 20

 

Arguments:
-s 15x15 -t square -B 20 -C 20 -e 1 -E gray

 

Arguments:
-B 20 -C 20

roundrectangle spotfile create as follows:

convert -size 20x10 xc:black \
+antialias -fill white \
-draw "roundrectangle 0,0 19,9 5,3" \
-alpha off -bordercolor black -border 1 \
roundrect_spotfile.png


What the script does is as follows:

  • Creates a spotfile for either a circle, square or diamond shape
    where the spot is white on a black background
  • Puts a black border around the spot cell
  • Compututes the cell size
  • Scales the image down and then back up to form uniform cells of color
  • Puts the tiled spotfile into the alpha channel of the blocked out image
  • Flattens the image over some background color

This is equivalent to the following IM commands for the case where no spotfile is provided no border is used.

  • ww=`convert $infile -ping -format "%w" info:`
  • hh=`convert $infile -ping -format "%h" info:`
  • sw=`echo $size | cut -dx -f1`
  • sh=`echo $size | cut -dx -f2`
  • scx=`convert xc: -format "%[fx:($sw-1)/2]" info:`
  • scy=`convert xc: -format "%[fx:($sh-1)/2]" info:`
  • lx=$((sw-1))
  • ly=$((sh-1))
  • pw=$((sw+2*pad))
  • ph=$((sh+2*pad))
  • if [ "$type" = "circle" ]; then
    convert -size ${sw}x${sh} xc:black \
    +antialias -fill white -draw "ellipse $scx,$scy $scx,$scy 0,360" -alpha off \
    padding="-bordercolor black -border $pad" \
    $tmpA2
    elif [ "$type" = "square" ]; then
    convert -size ${sw}x${sh} xc:black \
    +antialias -fill white -draw "rectangle 0,0 $lx,$ly" -alpha off \
    padding="-bordercolor black -border $pad" \
    $tmpA2
    elif [ "$type" = "diamond" ]; then
    convert -size ${sw}x${sh} xc:black \
    +antialias -fill white -draw "polygon $scx,0 $lx,$scy $scx,$ly 0,$scy" -alpha off \
    padding="-bordercolor black -border $pad" \
    $tmpA2
    fi
  • xmin=`convert xc: -format "%[fx:ceil($ww/$pw)]" info:`
  • ymin=`convert xc: -format "%[fx:ceil($hh/$ph)]" info:`
  • www=`convert xc: -format "%[fx:$xmin*$pw]" info:`
  • hhh=`convert xc: -format "%[fx:$ymin*$ph]" info:`
  • if [ "$edge" = "0" ]; then
    convert \( $infile -define distort:viewport=${www}x${hhh}+0 -virtual-pixel mirror -distort SRT 0 \
    -scale ${xmin}x${ymin}! -scale ${www}x${hhh}! -crop ${ww}x${hh}+0+0 +repage \) \
    \( $tmpA2 -write mpr:tile +delete -size ${ww}x${hh}! tile:mpr:tile \) \
    -alpha off -compose copy_opacity -composite -compose over \
    -background $bgcolor -flatten \
    $outfile
    else
    convert \( $infile -define distort:viewport=${www}x${hhh}+0 -virtual-pixel mirror -distort SRT 0 \
    -scale ${xmin}x${ymin}! -scale ${www}x${hhh}! -crop ${ww}x${hh}+0+0 +repage \) \
    \( $tmpA2 -write mpr:tile +delete -size ${ww}x${hh}! tile:mpr:tile \) \
    \( -clone 1 -threshold 0 -edge 1 -fill $ecolor -opaque white -transparent black \) \
    \( -clone 0 -clone 1 -alpha off -compose copy_opacity -composite -compose over \
    -background $bgcolor -flatten \) \
    -delete 0,1 +swap -compose over -composite \
    $outfile
    fi