Fred's ImageMagick Scripts


 

 

LUPE


Applies a magnifying glass effect in a local area of an image.

Download Script

last modified: May 30, 2008



USAGE: lupe [centx,centy] [-m mag] [-s shape] [-l lenx,leny] [-r round] [-b border] [-c color] [-d distort] infile outfile
USAGE: lupe [-h or -help]

centx,centy ............ coordinate in image for center of lupe;
........................ default is center of image
-m .... mag ............ magnification factor; float; mag>=1;
........................ default=2
-s .... shape .......... shape is lupe (magnifying glass) shape;
........................ circle (ellipse) or square (rectangle);
........................ default=circle
-l .... lenx,leny ...... radii (circle) or half-width (square);
........................ must be greater than 0; default=64,64;
........................ if only one value is provided, it will
........................ be used in both dimensions.
-r .... round .......... rounding radius for corners of square;
........................ round>=0; default=10
-b .... border ........ border thickness for lupe; border>=0;
........................ default=4
-c .... color .......... border color for lupe; default=white
-d .... distort ........ spherical distortion factor; float;
........................ distort>=0; default=0

PURPOSE: To apply a magnifying glass effect in a local area of an image.

DESCRIPTION: LUPE applies a magnifying glass (lupe) effect in a local area of an image. The normal mode is a simple magnification with no distortion. However an option is provided to apply a spherical distortion. The lupe can have either a circular/elliptical shape or a (rounded) square/rectangular shape. The lupe border thickeness and color can also be specified.

ARGUMENTS:

centx,centy ... CENTX,CENTY are the coordinates in the image for the center of the lupe. If not specified, then the center of the image will be provided.

-m mag ... MAG is the magnificiation factor. Values must be greater than or equal to 1. Values may be floating point numbers. The default is 2.

-s shape ... SHAPE is the shape of the lupe. The shape may be circle or square. The default is circle.

-l lenx,leny ... LENX,LENY is either the radii for the circle/ellipse or the half-width for the square/rectangle. Values must be integers greater than 0. The default is 64,64.

-r round ... ROUND is the radius of the corner rounding for the shape=square option. Values must be integers greater than or equal to zero. The default is 10.

-b border ... BORDER is the border thickness of the lupe. Values must be integers greater than or equal to zero. The default=4.

-c color ... COLOR is the color of the border of the lupe. Color may be any valid IM color specification. Be sure to enclose in double quotes if not using a color name. The default=white.

-d distort ... DISTORT is the spherical distortion factor. Values may be floating point numbers greater than or equal to 0. The default=0 (no distortion). When values are greater than 0, the distortion is applied using -fx. Therefore, the processing will be slower.

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


Simple Magnification

Original Image

Arguments:
-s circle -m 1

Arguments:
-s circle -m 2

Arguments:
-s circle -m 3

Arguments:
-s square -m 1

Arguments:
-s square -m 2

Arguments:
-s square -m 3



Shape And Border Variations - Magnification 2

Original Image

Arguments:
-s circle -m 2 -l 64,64

Arguments:
-s circle -m 2 -l 64,32

Arguments:
-s square -m 2 -l 64,64

Arguments:
-s square -m 2 -l 64,32

Arguments:
-s circle -m 2 -c white

Arguments:
-s circle -m 2 -c deepskyblue

Arguments:
-s circle -m 2 -b 4

Arguments:
-s circle -m 2 -b 0

Arguments:
-s circle -m 2 -b 4

Arguments:
-s circle -m 1 -b 0 -d 1



Magnification Versus Distortion

Original Image

Arguments:
135,135 -s circle -l 64,32 -m 1

Arguments:
135,135 -s circle -l 64,32 -m 2

Arguments:
135,135 -s circle -l 64,32 -m 3

Arguments:
135,135 -s circle -l 64,32 -m 1 -d 1

Arguments:
135,135 -s circle -l 64,32 -m 1 -d 2

Arguments:
135,135 -s circle -l 64,32 -m 1 -d 3

Magnification Animation

Distortion Animation

 
 


What the script does is as follows:

  • Creates a binary mask image for the loop of the desired size and
    shape
  • Computes and magnifies/distorts a subsection of the image
  • Masks the magnified/distorted subsection so it is transparent outside
  • Composites the masked magnified/distorted subsection into the image
    at the proper location
  • Draws the lupe border into the image

This is equivalent to the following IM commands for
the case of simple magnification:

  • convert -size ${subwidth}x${subheight} xc:black -fill white \
    -draw "$shape $subcentx,$subcenty $lenx,$leny 0,360" $tmp0
  • convert $infile[$sub] -distort SRT "$subcentx,$subcenty $mag 0" $tmp1
  • convert $infile \( $tmp1 $tmp0 $tmp0 -compose multiply -composite \) \
    -geometry $sub -composite $tmp2
  • convert $tmp2 \
    -stroke $color -strokewidth $border \
    -fill none -draw "$shape $centx,$centy $lenx,$leny 0,360" \
    -stroke $color2 -strokewidth $border2 \
    -fill none -draw "$shape $centx,$centy $lenxo,$lenyo 0,360" \
    -stroke $color2 -strokewidth $border2 \
    -fill none -draw "$shape $centx,$centy $lenxi,$lenyi 0,360" \
    $outfile