 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Thrawn
Joined: 12 May 2008 Posts: 29 Location: Germany
|
Posted: Sat May 16, 2009 3:45 pm Post subject: ImageMagick Wrapper (stdlib) [r1, 2009-05-16] |
|
|
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
Last edited by Thrawn on Tue May 19, 2009 11:03 am; edited 4 times in total |
|
| Back to top |
|
 |
tidbit
Joined: 09 Mar 2008 Posts: 671 Location: USA
|
Posted: Sat May 16, 2009 4:03 pm Post subject: |
|
|
I have made a Montage GUI awhile ago.
maybe it could be of use? _________________ rawr. be very affraid
*poke*
Note: My name is all lowercase for a reason. |
|
| Back to top |
|
 |
Thrawn
Joined: 12 May 2008 Posts: 29 Location: Germany
|
Posted: Mon May 18, 2009 10:44 pm Post subject: |
|
|
| I've added some basic examples and a link to the supported image formats. |
|
| Back to top |
|
 |
tidbit
Joined: 09 Mar 2008 Posts: 671 Location: USA
|
|
| Back to top |
|
 |
mtemp
Joined: 12 May 2009 Posts: 19
|
Posted: Wed May 20, 2009 1:16 pm Post subject: Re: ImageMagick Wrapper (stdlib) [r1, 2009-05-16] |
|
|
| Thrawn wrote: | | Example 1. Create a 106x80px thumbnail from file[code] |
Hello Thrawn,
I am running Vista64 with Autothotkey and now I have installed the 64 Bit edition of ImageMagick. All seems to be ok.
But when I try your example I get the following error:
Do I have to include IM.ahk or something similar to get your script working und to create my own skripts with your wrapper?
Greetings, Carlos |
|
| Back to top |
|
 |
hugov
Joined: 27 May 2007 Posts: 2429
|
|
| Back to top |
|
 |
mtemp
Joined: 12 May 2009 Posts: 19
|
Posted: Wed May 20, 2009 1:31 pm Post subject: Re: ImageMagick Wrapper (stdlib) [r1, 2009-05-16] |
|
|
Thanks for your quick reply!
| HugoV wrote: | | Yes, use #include |
But even with "#Include IM.ahk" as first line in the example AHK file I get the same error...
Carlos |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 2693 Location: the tunnel(?=light)
|
Posted: Wed May 20, 2009 1:48 pm Post subject: |
|
|
Try modifying that line in example.ahk to this and try it again:
| Code: | | while (IM_MagickNextImage(wand) != MagickFalse) |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
hugov
Joined: 27 May 2007 Posts: 2429
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 2693 Location: the tunnel(?=light)
|
Posted: Wed May 20, 2009 2:06 pm Post subject: |
|
|
| HugoV wrote: | Odd, the example works for me without errors. What AHK version are you using?
Edit: did you install imagemagick? |
Yeah I just ran it too, no errors, so ignore me and listen to Hugo.  _________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
mtemp
Joined: 12 May 2009 Posts: 19
|
Posted: Wed May 20, 2009 2:11 pm Post subject: |
|
|
| sinkfaze wrote: | | Code: | | while (IM_MagickNextImage(wand) != MagickFalse) |
|
Ok, with the brackets there is no error message any more -- but the resized image is missing...
And there is no error in the following line, too:
| Code: | | if (IM_MagickWriteImages(wand,dir outFile,MagickTrue) == MagickFalse) |
Imagemagick is installed (I can run the sample script in the DOS box).
Autohotkey version 1.0.47.06 -- so I give the newest version a try...
Thanks again for your help.
Carlos |
|
| Back to top |
|
 |
mtemp
Joined: 12 May 2009 Posts: 19
|
Posted: Wed May 20, 2009 2:50 pm Post subject: |
|
|
With xp32 and the windows-dll version of imageMagick the script works, but not with the windows-x64-static - version. Maybe this could be the reason.
But now I must go home...
Carlos |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Thu Jul 02, 2009 11:06 am Post subject: |
|
|
@Thrawn: I can't get this to work when I change the folder setup to my liking. There must be something obvious I'm doing wrong, but I can't find it.
Could you have a look at the first example from this complete setup?
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|