Jump to content

Autoit3 and ImageMagick


dom3787
 Share

Recommended Posts

Hello, I'm trying to make a little application that would take a font, a background picture and a text file to generate automatically cards for a game. I could do this another way (let's say with photoshop for instance) but I'm actually doing this for a friend and I need to keep things very simple (as simple as filling a text file, launching my tool and hitting create button). That said, I found a script on the net, made in bash, using ImageMagick. Great, half way there, now all I have to do is coding this for Windows, and with Autoit since that's what I'm familiar with. With Google help, I found threads on the topic in this forum, however, most severely outdated.

The first thing is that I would like my tool to be portable, that is, to join the correct dll with my script and get it to work without my friend having to install ImageMagick, I know it's possible, I found infos on this in this forum.

Here is a topic about the >ImageMagick Object by ptrex. (2007)

The ImageMagickObject.dll has disappeared if you install the latest version of it. More than that, at the last page of this thread, user Sunaj says in 2009 that the dll is already not working anymore and that he had to find an older version... I managed to find the one he mentionned as "working" here : ImageMagick-6.3.9-0-Q8-windows-static

Apparently from my readings, only "static" versions worked, not "dynamic"...(don't ask me what it means..). Well, even with it, and using a code sample from trancexx in >that thread where they talk about registering the dll, I cannot manage to get this to work. This is the code I tried (from ptrex & trancexx), I'm on Windows 7x64, but compiled as x86, using the latest Autoit :

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

$sDll = @ScriptDir & "\ImageMagickObject.dll" ; or just name
$aCall = DllCall($sDll, "long", "DllRegisterServer")
If @error Or $aCall[0] Then MsgBox(262144, "ERROR", "Failed to register " & FileGetLongName($sDll))

Dim $img
Dim $ret

; Initialize error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$img = ObjCreate("ImageMagickObject.MagickImage.1")

$ret = $img.Convert("C:\40002902.jpg", _
        "-resize", "320x200", _
        "-sepia-tone", "70%", _
        "-format", "gif", _
        "C:\40002902_NEW.gif")


Func MyErrFunc()
$HexNumber=hex($oMyError.number,8)
Msgbox(0,"COM Error Test","We intercepted a COM Error !"     & @CRLF & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber             & @CRLF & _
             "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "     & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
SetError(1) ; to check for after this function returns
Endfunc

Const $ERROR_SUCCESS = 0

Dim $img
Dim $info
Dim $msgs
Dim $elem
Dim $sMsgs

; Initialize error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

; This is the simplest sample I could come up with. It creates
; the ImageMagick COM object and then sends a copy of the IM
; logo out to a JPEG image files on disk.
;
$img = ObjCreate("ImageMagickObject.MagickImage.1")
;
; The methods for the IM COM object are identical to utility
; command line utilities. You have convert, composite, identify,
; mogrify, and montage. We did not bother with animate, and
; display since they have no purpose in this context.
;
; The argument list is exactly the same as the utility programs
; as a list of strings. In fact you should just be able to
; copy and past - do simple editing and it will work. See the
; other samples for more elaborate command sequences and the
; documentation for the utility programs for more details.
;
$sMsgs = $img.Convert("logo:","-format","%m,%h,%w","logo.jpg")
;
; By default - the string returned is the height, width, and the
; type of the image that was output. You can control this using
; the -format "xxxxxx" command as documented by identify.
;


MsgBox (0,"info: ","Return = " & $sMsgs)

I just changed the location of ImageMagickObject.dll, trancexx had put @SystemDir and I've put it in my script dir and wrote @ScriptDir. What I'm getting is an error that I don't understand :

..\ImageMagick 6.3.9.0\49065-imagemagick-object.au3 (27) : ==> Variable must be of type "Object".:
$HexNumber=hex($oMyError.number,8)
$HexNumber=hex($oMyError.number,8)

It should be! (of type Object) ...the syntax is right from the help file. This is how to write a COM error handler.. I'm clueless, if anyone could help me understand, and even more, if you know the good way to proceed on using ImageMagick with Autoit I'll be grateful.

Thanks.

Edited by dom3787
Link to comment
Share on other sites

I'm not sure, because I don't see this piece:

..\ImageMagick 6.3.9.0\49065-imagemagick-object.au3 (27) : ==> Variable must be of type "Object".:
$HexNumber=hex($oMyError.number,8)
$HexNumber=hex($oMyError.number,8)

at the rest of your code, but there is no ending quotation mark, so probably there is no opening quotation mark.

..\ImageMagick 6.3.9.0\49065-imagemagick-object.au3 

It has to be in quotation marks.

Link to comment
Share on other sites

  • Moderators

Mharsy,

The items you refer to as "this piece" are the error report in the SciTE console. There is absolutely no reason to expect any quotation marks there at all. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba23 is right. Anyway, I found the error, totally by chance, because I saw that it outputted a correct sepia jpg and I didn't notice it before so I figured out the crash was happening after it, then looking at the code I found a duplicate (copy/pasted) line. Actually, in its original thread, ptrex duplicated the whole MyErrFunc function, it was pretty obvious so I removed the unneccessary dupe, but what I didn't notice is that he also copy/pasted a call to that function. If you check the code I posted, there's an error handler creation line that shouldn't be there.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

All in all this code works.

Link to comment
Share on other sites

By the way, I'd like to unregister the dll at my program's shutdown, but :

$sDll = @ScriptDir & "\ImageMagickObject.dll" ; or just name
$aCall = DllCall($sDll, "long", "DllUnRegisterServer")
If @error Or $aCall[0] Then MsgBox(262144, "ERROR", "Failed to unregister " & FileGetLongName($sDll))

Throws the error, I checked with Regedit and the CLSID is indeed there, besides, my program works so it's expected. If I'm using regsvr32.exe /u in a command prompt to unregister it, it works, but when I'm doing it in the code with what I posted above, it doesn't work.. any idea?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...