[!] ****** ImageMagick Functions ********
** FILE: IM_Functions.inc
** Version: 1.0
** By: Terry Wilson, Terryfic.com
** Description: Use the ImageMagick suite of programs for Extending WebDNA.
Sandbox environment or primary WebDNA install.
More info on ImageMagick, including installers and instructions
can be found at their website, http://www.imagemagick.org
Advanced users: Learn more about the power of ImageMagick at the above site,
join the mailing list, and eventually create your own custom functions.
** How To Use: can be "[included]'ed" into the top
of any WebDNA template, or can be added to your "FunctionDefs/" directory to be used
as a pre-parse script for global access.
** REQUIREMENTS: WebDNA 6.x and above
** function naming convention prefix "im"; those for Sandbox users appended with SB
** Part of IMFunctions.zip package with ready-made usage template
** Change History:
Initial revision: Terry Wilson June 17, 2009
************ NOTE for SANDBOX Environments ********
For security reasons, Sandbox environments cannot run the [shell] script directly. However, you
can run all of these IM scripts quite easily by having just one sandbox script configured by your
administrator. Please refer to the ReadMe file for further Sandbox instructions.
****************************************************
NOTES:
1. The first function includes a practical example. The rest of them don't, but
you should be able to understand how it works based on the first one. The template
IM_Manipulation.html contains more comprehensive working examples, and is an entire
template ready to use for manipulating individual files.
Sandbox users: The usage info for each function shows text variables being set. If you are
sending these variables in from a form submission, you won't need to explicitly set them again...
they are already there. So conceivably, the Sandbox usage can be as simple as [imResizeImageSB].
2. RGB or grayscale is assumed
3. Each function requires a fileIn and fileOut definition. If you want to overwrite
the original file, just make the fileOut the same as the fileIn.
4. The Sitewide Setting below needs to be confirmed or edited to reflect
the path to ImageMagick on your server.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++ SITEWIDE SETTING: PathToIM ++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
** Description: defines the path to ImageMagick. Likely, this is /sw/bin/
** Used in the non-sandbox functions below. Sandbox users: does not apply.
** Note that Imagemagick is not one app, but a suite of apps; therefore this path
is to Imagemagick's parent directory, excluding the application name itself,
which is taken care of in the individual functions. All of these functions use
the convert program, but for future expansion, we will likely use some of the other ones.
[/!][text]PathToIM=/sw/bin[/text][!]
*************************** THE ***************************
************************ FUNCTIONS ************************
***********************************************************
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FUNCTION Name: imList
** Description: List all function names availabe in this
Library.
** Input: none
** ouput: function names
[/!][function name=imList]
[return][grep search=%09&replace=][grep search=[%0D%0A]&replace= ]
imList - List all function names available in this library. Functions appended with SB are for Sandbox installations.
imResizeImage/imResizeImageSB - Proportionately resize images to your chosen maximum width and height. (Does not enlarge.)
imMakeThumb/imMakeThumbSB - Proportionately creates thumbnails for images, within your maximum width or height.
imImprintText/imImprintTextSB - imprints solid text onto your image, as in a credit line or caption.
imRotate/imRotateSB - Rotates image in 90 degree increments.
imMirror/imMirrorSB - Mirrors image according to input, either vertically or horizontally.
imChangeFormat/imChangeFormatSB - Change format to jpg, gif, or png.
[/grep][/return]
[/function][!]
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FUNCTION Name: imResizeImage
** Description: Proportionately resize images to your chosen maximum width and height,
so you can upload without having to worry about final size beforehand.
** This will NOT enlarge files smaller than your maximum values.
** Code will retain the existing file format.
To change file format, use the imChangeFormat function. OR, renaming the destination
file to the preferred extension will automatically change the format as well.
** Input:
maxWidth = (maximum pixel width)
maxHeight = (maximum pixel height)
FileIn = (path to original file)
FileOut = (path to final destination)
** usage:
[imResizeImage FileIn=