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.

GLASSEFFECTS


Modifies an image so that it appears to be viewed through textured and/or tiled glass.

Download Script

last modified: December 15, 2018



USAGE: glasseffects [-e effect ] [-a amount] [-d density] [-g granularity] [-k kind] [-t type] [-m mode] [-w weight] [-s spacing] [-r ripple] [-b bluramt] [-c cellsize] [-o ocolor] [-i intermix] [-n newseed] infile outfile
USAGE: glasseffects [-h or -help]

-e .... effect ........... type of image effect; displace, disperse or none;
.......................... default=disperse
-a .... amount ........... amount of effect; integer>=0; zero indicates no
.......................... image effect; default=3
-d .... density .......... density (frequency) of dispersion; integer>=0; default=3
-g .... granularity ...... granularity (extent) of dispersion or displacement;
.......................... integer>=0; default=3
-k .... kind ............. kind of grid; simple or broken; default=simple
-t .... type ............. type of grid; grid; single, double or bipolar
.......................... default=single
-m .... mode ............. mode of applying grid; overlay (only for type!=bipolar) or
.......................... displace (all types) or grid (grid only, no image);
.......................... default=displace
-w .... weight ........... grid line weight; integer>=0; zero indicates no grid;
.......................... default=1
-s .... spacing .......... spacing between double or bipolar grid lines;
.......................... integer>=0; default=0
-r .... ripple ........... ripple (wiggle) amount for grid lines; integer>=0;
.......................... default=0
-b .... bluramt .......... blur amount for grid lines; float>=0; default=0
-c .... cellsize ......... grid cell size; comma separate x,y sizes; if only one
.......................... value is supplied it will be used for both;
.......................... integer>(2*weight+spacing); default=30
-o .... ocolor ........... grid overlay color; default=white
-i .... intermix ......... grid overlay color intermix with image percent;
.......................... 0<=integer<=100; default=100 indicates full grid and
.......................... no mixing with underlying image
-n .... newseed .......... forced seed value; integer>0; default will randomly
.......................... change seed

PURPOSE: To modify an image so that it appears to be viewed through textured and/or tiled glass.

DESCRIPTION: GLASSEFFECTS modifies an image so that it appears to be viewed through textured and/or tiled glass. The effect may be created using either displacement or dispersion. Also a grid may be superimposed, which can either be colored or used displaced image texture.

ARGUMENTS:

-e effect ... EFFECT applies either a displacement or dispersion effect to the image. Choices are: disperse, displace or none. The default is disperse.

-a amount ... AMOUNT of dispersion or displacement in pixels. Values are integers>=0. A value of zero will be the same as effect=none. The default=3.

-d density ... DENSITY is the density or frequency of the dispersion effect. Values are integers>=0. The default=3.

-g granularity ... GRANULARITY is the size of the dispersion or displacement areas. Values are integers>=0. The default=3.

-k kind ... KIND of grid desired. Choices are: simple or broken. Simple means continuous lines. Broken means the grid lines will be broken so the cells are somewhat separated and offset slightly. The default is simple.

-t type ... TYPE of grid desired. Choices are: single, double or bipolar. Single is a white grid on a black or gray background depending upon whether mode is set to overlay or displace, respectively. Double has the white grid lines doubled with an optional spacing between. Bipolar has double grid lines with an optional spacing between but one set is white and the other is black and they are both on a gray background as bipolar can only be used with mode=displace. The default is single.

-m mode ... MODE of applying the grid to the image. Choices are: displace (which can be use for all types), overlay (which is valid only for single or double grid types) and grid (which indicates to output only the grid and ignore the image). Using mode=displace will cause the texture of the grid to come from the image offset by a displacement of 1/4 of the grid cell size. If the grid is single or double, the offset will come from the right or down from the grid by 1/4 of the cell size (due to the grid being white). If the grid is bipolar, then the offset will be 1/4 of the cell size from that edge of the grid towards the interior of the cell (due to the grid being composed of both black and white parts). That is, the white grid will get its texture from the right or down by 1/4 of the cell size and the black grid will get its texture from the left or up by 1/4 of the cell size. Using mode=overlay will simply mix the specified color with the image where the grid exists. The default is displace.

-w weight ... WEIGHT is the line weight for the grid lines. Values are integers>=0. If zero is selected, then the grid will not be applied. The default=1.

-s spacing ... SPACING is the spacing between either the double or bipolar grid lines. Values are integers>=0. If zero is selected, there will be no space between the double or bipolar grid. Thus a spacing of zero for double grid lines is equivalent to twice the weight for a single grid lines. The default=0.

-r ripple ... RIPPLE indicates have the grid lines ripple or wiggle rather than being straight lines. Values are integers>=0. The default=0 which indicates no ripple.

-b bluramt ... BLURAMT is the amount of blurring to apply to the grid lines. This is only relevant to mode=overlay. Values are integers>=0. The default=0.

-c cellsize ... CELLSIZE is a comma separate pair of integers that represent the dimensions of the grid cells. If only one value is supplied, then it will be used for both dimensions. The cell size values must be larger than (2*weight+spacing) and cannot be zero. The default=30

-o ocolor ... COLOR is the mixing color for the grid with the image when mode=overlay. Any valid IM color is allowed. The default=white. See http://imagemagick.org/script/color.php

-i intermix ... INTERMIX is the mixing percent of the overlay color of the grid with the image background. Values are integers between 0 and 100. The default=100 indicates that the grid will be full overlay color and will not be mixed with the underlying image.

-n newseed ... NEWSEED is the forced seed value to use for randomization in the image effect and in the ripple. This permits the pattern to be repeated. The default is to change the seed value randomly each time the script is run, thus causing somewhat different patterns each time the script is run.

NOTE: If your IM version is less than 6.4.8.4, then the dispersion effect will run slowly due to the use of -fx.

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: Disperse Vs Displace --- No Grid

Original

Disperse
Arguments:
-e disperse -a 3 -d 3 -g 3 -w 0 -n 100

Displace
Arguments:
-e displace -a 10 -g 3 -w 0 -n 100



Example 2: Disperse With Displaced Simple Grid And Increasing Width And Spacing

Original

Single
Arguments:
-e disperse -k simple
-t single -m displace
-a 3 -d 3 -g 3 -w 1 -n 100

 

Bipolar
Arguments:
-e disperse -k simple
-t bipolar -m displace
-a 3 -d 3 -g 3 -w 1 -n 100

 

 

Double
Arguments:
-e disperse -k simple
-t double -m displace
-a 3 -d 3 -g 3 -w 1 -s 1 -n 100

Bipolar
Arguments:
-e disperse -k simple
-t bipolar -m displace
-a 3 -d 3 -g 3 -w 1 -s 1 -n 100

 

Single
Arguments:
-e disperse -k simple
-t single -m displace
-a 3 -d 3 -g 3 -w 2 -n 100

 

Bipolar
Arguments:
-e disperse -k simple
-t bipolar -m displace
-a 3 -d 3 -g 3 -w 2 -n 100

 

 

Double
Arguments:
-e disperse -k simple
-t double -m displace
-a 3 -d 3 -g 3 -w 2 -s 1 -n 100

Bipolar
Arguments:
-e disperse -k simple
-t bipolar -m displace
-a 3 -d 3 -g 3 -w 2 -s 1 -n 100

 

 

Double
Arguments:
-e disperse -k simple
-t double -m displace
-a 3 -d 3 -g 3 -w 2 -s 2 -n 100

Bipolar
Arguments:
-e disperse -k simple
-t bipolar -m displace
-a 3 -d 3 -g 3 -w 2 -s 2 -n 100

 


Example 3: Overlay Grids (No Disperse Or Displace)

Original

Single Simple
Arguments:
-e none -k simple
-t single -m overlay
-o darkgoldenrod -w 2

Single Broken
Arguments:
-e none -k broken
-t single -m overlay
-o darkgoldenrod -w 2

Single Simple Wiggle
Arguments:
-e none -k simple
-t single -m overlay
-o darkgoldenrod -w 2 -r 5

Double Simple Wiggle
Arguments:
-e none -k simple
-t double -m overlay
-o darkgoldenrod -w 2 -s 2 -r 5



Example 4: Overlay Grids With Dispersion

Original

Single Simple
Arguments:
-e disperse -k simple
-t single -m overlay
-o darkgoldenrod -w 2
-a 3 -d 3 -g 3 -n 100

Single Broken
Arguments:
-e disperse -k broken
-t single -m overlay
-o darkgoldenrod -w 2
-a 3 -d 3 -g 3 -n 100

Double Simple
Arguments:
-e disperse -k simple
-t double -m overlay
-o darkgoldenrod -w 2 -s 2
-a 3 -d 3 -g 3 -n 100

Double Simple Wiggle
Arguments:
-e disperse -k simple
-t double -m overlay
-o darkgoldenrod -w 2 -s 2
-a 3 -d 3 -g 3 -r 5 -n 100

Single Simple Intermix
Arguments:
-e disperse -k simple
-t single -m overlay
-o darkgoldenrod -w 2 -i 50
-a 3 -d 3 -g 3 -n 100

Single Simple Blur
Arguments:
-e disperse -k simple
-t single -m overlay
-o darkgoldenrod -w 2 -b 1
-a 3 -d 3 -g 3 -n 100



Example 5: Grids

Original

Single Simple
Arguments:
-k simple -t single
-m grid -w 2

Single Broken
Arguments:
-k broken -t single
-m grid -w 2

Bipolar Simple
Arguments:
-k simple -t bipolar
-m grid -w 2 -s 0

Double Simple
Arguments:
-k simple -t double
-m grid -w 2 -s 2



Example 6: Disperse Vs Displace --- With Bipolar Grid
(http://www.entheosweb.com/photoshop/glass_effects.asp)

Original

Disperse
Arguments:
-e disperse -k simple
-t bipolar -m displace
-a 3 -d 3 -g 3 -w 1 -s 1 -n 100

Displace
Arguments:
-e displace -k simple
-t bipolar -m displace
a 10 -g 3 -w 1 -s 1 -n 100



What the script does is as follows:

  • Creates a random, blurred image
  • Applies the random, blurred image to the input image
    as a displacement map or as a dispersion map
  • Optionally creates a grid
  • Applies the grid to the image either as an overlay of
    specified color or uses image texture from a displacement

This is equivalent to the following IM commands for effect=disperse, kind=simple,
mode=displace, type=bipolar

  • ww=`convert $infile -format "%[fx:w]" info:`
  • hh=`convert $infile -format "%[fx:h]" info:`
  • xcell=`convert xc: -format "%[fx:$xsize - $weight]" info:`
  • ycell=`convert xc: -format "%[fx:$ysize - $weight]" info:`
  • ww2=`convert xc: -format "%[fx:$ww - $weight]" info:`
  • hh2=`convert xc: -format "%[fx:$hh - $weight]" info:`
  • convert -size ${ww}x${hh} xc: $seeding +noise Random -colorspace gray \
    -blur 0x${granular} -virtual-pixel tile -fx "u" -contrast-stretch 0% $tmp1
  • convert $infile \
    \( $tmp1 -evaluate cos "$density" \) \
    \( $tmp1 -evaluate sin "$density" \) \
    -compose displace -set option:compose:args ${amount}x${amount} -composite $tmp0
  • convert \( -size ${xcell}x${ycell} xc:black \
    -size ${weight}x${ycell} xc:white +append \
    -size ${xcell}x${weight} xc:white -append \) \
    -write mpr:tile +delete -size ${ww}x${hh} tile:mpr:tile \
    -gravity southeast -chop ${weight}x${weight}+0+0 \
    \( +clone -gravity east -crop ${weight}x${hh2}+0+0 +repage \) +append \
    \( +clone -gravity south -crop ${ww}x${weight}+0+0 +repage \) -append $tmp2
  • convert $tmp2 \( +clone -negate -roll -${offset}-${offset} +level 0,50% \) \
    -compose plus -composite $tmp2
  • if [ "$spacing" = "" ]; then
    dx=`convert xc: -format "%[fx:($xsize-$weight)/4]" info:`
    dy=`convert xc: -format "%[fx:($ysize-$weight)/4]" info:`
    else
    dx=`convert xc: -format "%[fx:($xsize-$weight-$spacing)/4]" info:`
    dy=`convert xc: -format "%[fx:($ysize-$weight-$spacing)/4]" info:`
    fi
  • composite $tmp2 $tmp0 -virtual-pixel edge -displace ${dx}x${dy} $outfile