AutoHotkey Community

It is currently May 26th, 2012, 7:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: May 16th, 2009, 4:45 pm 
Offline

Joined: May 12th, 2008, 2:23 pm
Posts: 30
Location: Germany
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 May 19th, 2009, 12:03 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2009, 5:03 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
I have made a Montage GUI awhile ago.
maybe it could be of use?

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2009, 11:44 pm 
Offline

Joined: May 12th, 2008, 2:23 pm
Posts: 30
Location: Germany
I've added some basic examples and a link to the supported image formats.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2009, 2:38 am 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
broken URL for file type link.
you have: http://www.imagemagick.org/script/formats.php[/url
need: http://www.imagemagick.org/script/formats.php

nice wrapper.
though the names are kinda long :P

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 20th, 2009, 2:16 pm 
Offline

Joined: May 12th, 2009, 3:36 pm
Posts: 27
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:
Image

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 20th, 2009, 2:25 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
mtemp wrote:
Do I have to include IM.ahk or something similar to get your script working und to create my own skripts with your wrapper?

Yes, use #include or place them in your library see http://www.autohotkey.com/docs/Functions.htm#lib

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 20th, 2009, 2:31 pm 
Offline

Joined: May 12th, 2009, 3:36 pm
Posts: 27
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2009, 2:48 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Try modifying that line in example.ahk to this and try it again:

Code:
while (IM_MagickNextImage(wand) != MagickFalse)

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2009, 2:58 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Odd, the example works for me without errors. What AHK version are you using?

Edit: did you install imagemagick?

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2009, 3:06 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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. :)

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2009, 3:11 pm 
Offline

Joined: May 12th, 2009, 3:36 pm
Posts: 27
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2009, 3:50 pm 
Offline

Joined: May 12th, 2009, 3:36 pm
Posts: 27
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 12:06 pm 
@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?

:(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2010, 8:44 pm 
Offline

Joined: May 12th, 2009, 3:36 pm
Posts: 27
Hmm, I found my own message in this thread...

Once again, working with Vista64

ImageMagick as 64-DLL is working correctly. At least I can run convert, identify, imdisplay from the command line.

Then I tried example 1. But there is infinite looping at this point:
Image

The empty message box appears in a loop...

Any suggestions?
carlos


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: infogulch, tomoe_uehara, Xx7 and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group