ImageMagick Wrapper Release 1, 2009-05-16
Quote:
ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
This is a wrapper for MagickWand
Quote:
The MagickWand API is the recommended interface between the C programming language and the ImageMagick image processing libraries. Unlike the MagickCore C API, MagickWand uses only a few opaque types. Accessors are available to set or get important wand properties.
Example 1. Create a 106x80px thumbnail from file
Code:
dir := A_ScriptDir "\"
inFile := "testimg.jpg"
outFile := "resampled_" inFile
;load the dll
hDll := IM_LoadDLL()
;initializs the MagickWand environment
IM_MagickWandGenesis()
IM_GlobalConstants()
;NewMagickWand() returns a wand required for all other methods in the API.
wand := IM_NewMagickWand()
if(IM_MagickReadImage(wand,dir inFile) == MagickFalse)
msgbox, Error @ Readimage
;MagickResetIterator() resets the wand iterator.
; Use it in conjunction with MagickNextImage() to iterate over all
; the images in a wand container.
IM_MagickResetIterator(wand)
;Iterate over all the images in the wand container
;and resize them to 106x80px, using LanczosFilter
while IM_MagickNextImage(wand) != MagickFalse
IM_MagickResizeImage(wand,106,80,LanczosFilter,1.0)
;Write the images...
if(IM_MagickWriteImages(wand,dir outFile,MagickTrue) == MagickFalse)
msgbox, Error @ Writeimage
;...then destroy it.
magick_wand := IM_DestroyMagickWand(wand)
;terminate the MagickWand environment.
IM_MagickWandTerminus()
IM_UnloadDLL(hDll)
Example 2. Create thumbnail from the IM-Logo, draw a 2px black border around it and save as tif, gif, psd, png, pcx, bmp, tga and raw-txt.
Code:
outFile := A_ScriptDir "\example2."
;load the dll
hDll := IM_LoadDLL()
;initializs the MagickWand environment
IM_MagickWandGenesis()
IM_GlobalConstants()
;NewMagickWand() returns a wand required for all other methods in the API.
wand := IM_NewMagickWand()
p_wand := IM_NewPixelWand()
IM_PixelSetColor(p_wand, "black")
IM_MagickReadImage(wand,"logo:")
w := IM_MagickGetImageWidth(wand)
h := IM_MagickGetImageHeight(wand)
IM_MagickSetImageBackgroundColor(wand,p_wand)
;resize img to 106x80px, using LanczosFilter
IM_MagickResizeImage(wand,106,80,LanczosFilter,1.0)
w := IM_MagickGetImageWidth(wand)
h := IM_MagickGetImageHeight(wand)
IM_MagickExtentImage(wand,w+4,h+4,-2,-2)
IM_MagickSetImageCompressionQuality(wand,75)
;Write the image
outputFormats = jpg,tif,gif,psd,png,pcx,bmp,tga,txt
loop, parse, outputFormats, `,
{
if(IM_MagickWriteImage(wand,outFile A_LoopField) == MagickFalse)
msgbox, Error @ Writeimage (%A_LoopField%)
}
;...then destroy it.
wand := IM_DestroyMagickWand(wand)
p_wand = DestroyPixelWand(p_wand)
;terminate the MagickWand environment.
IM_MagickWandTerminus()
IM_UnloadDLL(hDll)
Example 3: Convert between image formats
Code:
;load the dll
hDll := IM_LoadDLL()
;initializs the MagickWand environment
IM_MagickWandGenesis()
inFile := A_ScriptDir "\testimg.jpg"
outFile := A_ScriptDir "\example3.png"
convertImage(inFile,outFile)
;terminate the MagickWand environment.
IM_MagickWandTerminus()
IM_UnloadDLL(hDll)
convertImage(inFile,OutFile,quality=75)
{
;NewMagickWand() returns a wand required for all other methods in the API.
wand := IM_NewMagickWand()
;Read the image
if(IM_MagickReadImage(wand,inFile) == 0)
msgbox, Error @ Readimage (%inFile%)
;Set compression quality
IM_MagickSetImageCompressionQuality(wand,quality)
;Write the image
if(IM_MagickWriteImage(wand,outFile) == 0)
msgbox, Error @ Writeimage (%outFile%)
;...then destroy it.
wand := IM_DestroyMagickWand(wand)
}
IM.ahk (126kb)
Download source + example (zip, 80kb)
ImageMagick Download You want one of the dll releases
Documentation
Supported Fileformats