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

TOYCAMERA


Simulates pictures taken by lomographic or holga type toy cameras.

Download Script

last modified: May 03, 2015



USAGE: toycamera [-g] [-i inner] [-o outer] [-d dark] [-f feather] [-b bri] [-s sat] [-h hue] [-c contr] [-t tint] [-a amount] [-S sharp] [-I iblur] [-O oblur] [-B barrel] [-D double] infile outfile
USAGE: toycamera [-help]

-g ............... convert image to grayscale
-i ... inner ..... inner radius of vignette where not darkened;
.................. integer percent of image dimension; default=0
-o ... outer ..... outer radius of vignette where darkest;
.................. integer percent of image dimension; default=150
-d ... dark ...... graylevel of darkest part of vignette in integer
.................. range 0 to 100; default=0
-f ... feather ... feathering amount for inner radius; float>=0;
.................. default=0
-b ... bri ....... modulation brightness change percent; integer;
.................. default=0
-s ... sat ....... modulation saturation change percent; integer;
.................. default=0
-h ... hue ....... modulation hue change percent; integer; default=0
-c ... contr ..... contrast change percent; integer; default=0
-t ... tint ...... tint color; any IM opaque color; default=no tint
-a ... amount .... tint amount; integer>=0; default=0
-S ... sharp ..... sharpening amount; float>=0; default=0
-I ... iblur ..... inner blurring amount; float>=0; default=0
-O ... oblur ..... outer blurring amount; float>=0; default=0
-B ... barrel .... barrel distortion; float>=0; default=0
-D ... double .... doubling distortion spacing; integer>=0; default=0

PURPOSE: Simulates pictures taken by lomographic or holga type toy cameras.

DESCRIPTION: TOYCAMERA simulates pictures taken by lomographic or holga type toy cameras. These cameras have numerous distortions due to the cheap plastic lenses. Some of these distortions include: vignetting, high saturation, blurring, barrel distortion and image doubling. Typically these cameras shoot square images, but I have left that more flexible here and up to the user to crop the image first.

ARGUMENTS:

-g ... First convert image to grayscale.

-i inner ... INNER vignette radius as percent of image dimension. The default=0 means the vignette starts near the image center.

-o outer ... OUTER vignette radius as percent of image dimension. The default=150, which is about the image corners.

-d dark ... DARK the graylevel of the darkest part of the vignette in the range 0 to 100, where 0 is black and 100 is white. The default=0

-f feather ... FEATHER is the amount of feathering or smoothing of the transition around the inner radius. Values are floats>0. The default=0

-b bri ... BRI is the percent change in brightness. Values are integers. The default=0 or no change.

-s sat ... Sat is the percent change in saturation. Values are integers. The default=0 or no change.

-h hue ... HUE is the percent change in brightness. Values are integers. The default=0 or no change.

-c contr ... CONTR is the percent change in contrast. Values are integers. The default=0 or no change.

-t tint ... TINT is the overal tinting color. Any valid opaque IM color is allowed. The default=no tinting.

-a amount ... AMOUNT is the overal tinting amount. Values are integers in the range 0 to 100. The default=0 meaning no tinting.

-S sharp ... SHARP is the amount of sharpening to apply in the inner region. Values are floats>0. The default=0

-I iblur ... IBLUR is the amount of blurring to apply in the inner region. Values are floats>0. The default=0

-O oblur ... IBLUR is the amount of blurring to apply in the outer region. Values are floats>0. The default=0

-B barrel ... Barrel is the amount of barrel/pincussion distortion to apply. Values are floats. Positive values produce barrel distortion. Negative values produce pincussion distortion. Typical values are in the range -5 to +5. The default=0 meaning no distortion.

-D double ... DOUBLE is the doubling distortion spacing in the X and Y directions. Values are comma separate integer pairs with + or - signs. There must be no spaces and the signs are required. The default=+0,+0 means no doubling. Nominal values are about 3. The values are used by the -roll function to simulate chromatic abberation for grayscale images.

Requirements: IM 6.5.9-0 to support the -brightness-contrast function.

Reference:
http://photoshoptutorials.ws/photoshop-tutorials/photo-effects/lomography.html
http://photoshopgirl.com/01/29/holga-medium-format-effect
http://flareapp.tumblr.com/post/3875359029/simulating-the-holga-120-toy-camera
http://en.wikipedia.org/wiki/Holga
http://en.wikipedia.org/wiki/Lomography

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

Original
(http://photoshoptutorials.ws/photoshop-tutorials/photo-effects/lomography.html)

Arguments:
-i 50 -o 150 -s 100 -O 3 -I 3



Example 2 - holga

Original
(http://photoshopgirl.com/01/29/holga-medium-format-effect)

Arguments:
-i 5 -o 150 -d 5 -h -3 -t yellow -a 10 -I 0.75 -O 5



Example 3 - holga

Original
(http://www.webdesign.org/web/photoshop/photoshop-basics/photo-correction-101-auto-color.8149.html)

Arguments:
-g -i 30 -o 200 -d 20 -f 20 -b 5 -S 2 -B 5 -D +3,+0



What the script does is as follows for mode=intensity:

  • Converts the image to grayscale if desired
  • Process the image to adjust brightness, saturation, hue,
    contrast, blurring, sharpening, barrel distortion and doubling
  • Applies an adjustable vignette

This is equivalent to the following IM commands for mode=intensity:

  • if [ "$gray" = "no" ]; then
    grayish=""
    else
    grayish="-colorspace gray"
    fi
  • convert -quiet -regard-warnings "$infile" $grayish +repage "$tmpA1"
  • ww=`convert $tmpA1 -format "%w" info:`
  • hh=`convert $tmpA1 -format "%h" info:`
  • wwo=`convert xc: -format "%[fx:$outer*$ww/100]" info:`
  • hho=`convert xc: -format "%[fx:$outer*$hh/100]" info:`
  • mwh=`convert xc: -format "%[fx:$outer*min($ww,$hh)/100]" info:`
  • if [ "$inner" = "0" ]; then
    mlevel=""
    else
    inner=$((100-inner))
    mlevel="-level 0x$inner%"
    fi
  • if [ "$dark" = "0" ]; then
    plevel=""
    else
    plevel="+level ${dark}x100%"
    fi
  • if [ "$iblur" = "0" ]; then
    iblurring=""
    else
    iblurring="-blur 0x$iblur"
    fi
  • if [ "$oblur" = "0" ]; then
    oblurring=""
    else
    oblurring="-blur 0x$oblur"
    fi
  • if [ "$feather" = "0" ]; then
    feathering=""
    else
    feathering="-blur ${feather}x65000"
    fi
  • if [ "$sharp" = "0" ]; then
    sharpening=""
    else
    sharpening="-sharpen 0x$sharp"
    fi
  • if [ "$contr" = "0" ]; then
    contrasting=""
    else
    contrasting="-brightness-contrast 0,$contr"
    fi
  • if [ "$bri" = "0" -a "$sat" = "0" -a "$hue" = "0" ]; then
    modulation=""
    else
    bri=$((100+bri))
    sat=$((100+sat))
    hue=$((100+hue))
    modulation="-modulate $bri,$sat,$hue"
    fi
  • if [ "$barrel" = "0" ]; then
    distorting=""
    else distort=`convert xc: -format "%[fx:$barrel/100]" info:`
    test=`convert xc: -format "%[fx:sign($distort)<0?1:0]" info:`
    if [ $test -eq 1 ]; then
    distort1=`convert xc: -format "%[fx:1+2*$distort]" info:`
    else
    distort1=`convert xc: -format "%[fx:1-2*$distort]" info:`
    fi
    distorting="-distort barrel $distort,0,0,$distort1"
    fi
  • if [ "$tint" = "" -o "$amount" = "0" ]; then
    tinting=""
    else
    tinting="-fill $tint -colorize $amount%"
    fi
  • if [ "$double" = "+0,+0" -o "$double" = "-0,-0" ]; then
    rolling1=""
    rolling2=""
    rolling3=""
    else xroll=`echo $double | cut -d, -f1`
    yroll=`echo $double | cut -d, -f2`
    rolling1="+clone -roll ${xroll}${yroll}"
    rolling2="-compose blend -define compose:args=50,50 -composite -compose over"
    axroll=`convert xc: -format "%[fx:abs($xroll)]" info:`
    ayroll=`convert xc: -format "%[fx:abs($yroll)]" info:`
    rolling3="-shave ${axroll}x${ayroll}"
    fi
  • convert \( $tmpA1 \( $rolling1 \) $rolling2 $contrasting $iblurring $sharpening $distorting \) \
    \( +clone $oblurring \) \
    \( -size ${mwh}x${mwh} radial-gradient: -resize ${wwo}x${hho}! \
    -gravity center -crop ${ww}x${hh}+0+0 +repage \) \
    \( +clone $mlevel $plevel -clamp $feathering $tinting \) \
    \( -clone 1 -clone 0 -clone 2 -clamp -compose over -composite $modulation \) \
    -delete 0-2 +swap -compose multiply -composite $rolling3 $outfile