Jump to content



Photo

ImageMagick Object


  • Please log in to reply
49 replies to this topic

#1 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 07 July 2007 - 08:41 PM

Image Processing in AU3 - IMAGEMAGICK

I saw someone mentioning IMAGEMAGICK in the support site,
and I remembered it has a huge number on command line options.

The later version has as well an COM object, that exposes all cmd line options via the object.
IMAGEMAGICK - COM Object

Perfect for AU3 wouldn't you say.

There are about 200 cmd line options. IMAGEMAGICK - Command line Options

This will get you all started.

AutoIt         
Dim $img Dim $ret ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $img = ObjCreate("ImageMagickObject.MagickImage.1") $ret = $img.Convert("C:Tempbill_meets_gorilla_screen.jpg", _         "-resize", "320x200", _         "-sepia-tone", "70%", _         "-format", "gif", _         "C:Tempbill_meets_gorilla_screen_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) 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



Enjoy !!

ptrex

Edited by ptrex, 14 September 2012 - 09:29 AM.

  • Sunaj likes this





#2 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 07 July 2007 - 10:50 PM

Very Cool. I might start creating a few 100 functions from this... :whistle:

#3 nobbe

nobbe

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 433 posts

Posted 08 July 2007 - 10:42 AM

hi
i started some code a while ago but didnt continue since i switched to nconvert (it has a com object too)

maybe someone may find it useful ..






; _imagemagick.au3
;
; for use with IMAGE magick ..
; http://www.imagemagick.org/
;
;
;
;
; command line tools syntax :: http://www.cit.gu.edu.au/~anthony/graphics/imagick6/

;===============================================================================
;
; Function Name:
; Description:
; Parameter(s):
;
;===============================================================================
;
Func _ImageMagick_Convert($infile, $outfile)
local $o_object;
local $rc;

$o_object = ObjCreate("ImageMagickObject.MagickImage.1")
If Not IsObj($o_object) Then
Return 0
endif

$rc = $o_object.Convert($infile, $outfile)

Return 1
EndFunc
;===============================================================================



;===============================================================================
;
; Function Name:
; Description:
; Parameter(s):
;
;===============================================================================
;
Func _ImageMagick_Resample($infile, $outfile, $percent)
local $o_object;
local $rc;
local $c;

$o_object = ObjCreate("ImageMagickObject.MagickImage.1")
If Not IsObj($o_object) Then
Return 0
endif

$c= $percent & "%x" & $percent & "%" ;

; -sample 25%x25%

$rc = $o_object.Convert("-sample", $c, $infile, $outfile)


Return 1
EndFunc


;===============================================================================
;
; Function Name:
; Description:
; Parameter(s):
;
;===============================================================================
;
; DOESNT WORK YET !!
;
;
Func _ImageMagick_Identify($infile)
local $o_object;
local $rc;
local $c;
Local $array ;

$o_object = ObjCreate("ImageMagickObject.MagickImage.1")
If Not IsObj($o_object) Then
Return 0
endif

;all output goes to STDOUT :: ? ??

$rc = $o_object.Identify($infile)

$var = ConsoleRead()
msgbox (0,"console",$var)

Return 1
EndFunc


;===============================================================================
;
; Function Name:
; Description:
; Parameter(s):
;
;===============================================================================
;
Func _ImageMagick_Addtext($infile , $outfile, $posx, $posy , $text)
local $o_object;
local $rc;
local $c;

$o_object = ObjCreate("ImageMagickObject.MagickImage.1")
If Not IsObj($o_object) Then
Return 0
endif

; build text "object" ..
;$rc = $IMG.Convert("-draw","text 10,20 'Works like magick'","logo.jpg","logo3a.gif") ;

$c="text " & $posx & "," & $posy & " '" &$text &"'" ;
$rc = $o_object.Convert("-draw", $c, $infile, $outfile) ;

Return 1
EndFunc

#4 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 08 July 2007 - 05:39 PM

@Bert

Thanks and happy scripting with your functions !!

@Nobbe

Thanks for your contribution.

I had a look at the Nconvert tool. But it does not seem to be for free all the way. Only for personal use.
Nevertheless it looks a powerfull tool as well.

Why did you decide to move to Nconvert from ImageMagick ?

regards,

ptrex

#5 CoderDunn

CoderDunn

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 345 posts

Posted 09 July 2007 - 01:28 AM

Cool. Now you have made my problem even easier! Thanks, this is alot better than the way I was doing it :whistle:

You should make some UDF's for this!

Hallman

Edited by Hallman, 09 July 2007 - 01:34 AM.


#6 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 09 July 2007 - 07:57 AM

@Hallman

Thanks.

Making life easier that's what AU3 is meant for not :whistle:

Maybe the Summer Holidays are good for making some UDF's.

regards,

ptrex

#7 ScriptLearner

ScriptLearner

    Seeker

  • Active Members
  • 31 posts

Posted 06 August 2007 - 09:12 AM

Plain Text         
Dim $img Dim $ret ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $img = ObjCreate("ImageMagickObject.MagickImage.1") $ret = $img.Convert("C:\Temp\bill_meets_gorilla_screen.jpg", _         "-resize", "320x200", _         "-sepia-tone", "70%", _         "-format", "gif", _         "C:\Temp\bill_meets_gorilla_screen_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ƒo݊÷ Ø  Ý¢Ø^­ìZš™^jëhŠ×6Const $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) 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


Thanks For This Should Help For Future Scripting

#8 footswitch

footswitch

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 08 September 2007 - 12:20 AM

When I tested this app, I used command line.
If I can remember it, ImageMagick needs to be installed and assigns a lot of system variables. Is there a way that doesn't need installing?

My target was to be able to carry a compiled script with me (for instance, on a CD or USB key) and run it in any machine, without having to install ImageMagick first.

So it would be like using ImageMagick's files in the same directory as my script or in an addon folder or something...

But COM Objects need app registration in the operating system and so on, am I right?


footswitch

#9 flyingboz

flyingboz

    The Network Is All

  • Active Members
  • PipPipPipPipPipPip
  • 768 posts

Posted 25 September 2007 - 09:33 PM

My target was to be able to carry a compiled script with me (for instance, on a CD or USB key) and run it in any machine, without having to install ImageMagick first.
But COM Objects need app registration in the operating system and so on, am I right?


the dll has to be registered, but this is an easily handled scenario -- assuming permissions aren't a problem.
Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

#10 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 25 September 2007 - 09:51 PM

I forgot completely about this... Meh. I must start to do this UDF. It is holiday time for me :)

Now i remember why i gave up. It was too damn hard... :)

Edited by Bert, 25 September 2007 - 11:21 PM.


#11 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 26 September 2007 - 06:50 AM

@Bert

Good to see that you are picking this up.

Because it's a long way, when you compaire all the options IMAGEMAGICK has.

But that's what holidays are good for, correct :)

regards

ptrex

#12 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 26 September 2007 - 07:02 AM

@Bert

Good to see that you are picking this up.

Because it's a long way, when you compaire all the options IMAGEMAGICK has.

But that's what holidays are good for, correct :)

regards

ptrex

So the page you gave us has all the "switches" for the actual image manipulation? So i could call 1 function, to do an umpteenth of those things? Maybe using a number? (2,4,8,16...) to tell what switches? hmmm.... but then you've got trouble with the values... maybe call one function to manipulate the the image, with that specific value.... I'm lost now :) Could you give me a pointer on how to go about this? And it doesn't help that Dial-up sucks... :P

#13 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 26 September 2007 - 07:17 AM

AutoIt         
; ---------------------------------------------------------------------------- ; Compare Options ; Option Description ;-alpha                 activate, deactivate, reset, or set the alpha channel ;-authenticate          value decrypt image with this password ;-channel type          apply option to select image channels ;-colorspace type       set image colorspace ;-debug events          display copious debugging information ;-define format:option  define one or more image format options ;-density geometry      horizontal and vertical density of the image ;-depth value           image depth ;-extract geometry      extract area from image ;-fuzz distance         colors within this distance are considered equal ;-help                  print program options ;-identify              identify the format and characteristics of the image ;-interlace type        type of image interlacing scheme ;-limit type            value pixel cache resource limit ;-log format            format of debugging information ;-metric type           measure differences between images with this metric ;-profile filename      add, delete, or apply an image profile ;-quality value         JPEG/MIFF/PNG compression level ;-quantize colorspace   reduce image colors in this colorspace ;-quiet                 suppress all warning messages ;-sampling-factor       geometry horizontal and vertical sampling factor ;-seed value            seed a new sequence of pseudo-random numbers ;-set attribute         value set an image attribute ;-size geometry         width and height of image ;-transparent-color     color transparent color ;-verbose print         detailed information about the image ;-version print         version information ;-virtual-pixel         method access method for pixels outside the boundaries of the image ; ---------------------------------------------------------------------------------- _compare(-metric PSNR rose.jpg, reconstruct.jpg, difference.png) Func _compare ($Option, $Source1, $Source2, $Output="difference.png") ; Code here EndFunc


Than the next functions : convert, composite, mogrify, identify, montage, and stream
And you are done.

Keeps you busy for a while.

Regards,

ptrex

#14 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 26 September 2007 - 07:50 AM

AutoIt         
; ---------------------------------------------------------------------------- ; Compare Options ; Option Description ;-alpha                 activate, deactivate, reset, or set the alpha channel ;-authenticate          value decrypt image with this password ;-channel type          apply option to select image channels ;-colorspace type       set image colorspace ;-debug events          display copious debugging information ;-define format:option  define one or more image format options ;-density geometry      horizontal and vertical density of the image ;-depth value           image depth ;-extract geometry      extract area from image ;-fuzz distance         colors within this distance are considered equal ;-help                  print program options ;-identify              identify the format and characteristics of the image ;-interlace type        type of image interlacing scheme ;-limit type            value pixel cache resource limit ;-log format            format of debugging information ;-metric type           measure differences between images with this metric ;-profile filename      add, delete, or apply an image profile ;-quality value         JPEG/MIFF/PNG compression level ;-quantize colorspace   reduce image colors in this colorspace ;-quiet                 suppress all warning messages ;-sampling-factor       geometry horizontal and vertical sampling factor ;-seed value            seed a new sequence of pseudo-random numbers ;-set attribute         value set an image attribute ;-size geometry         width and height of image ;-transparent-color     color transparent color ;-verbose print         detailed information about the image ;-version print         version information ;-virtual-pixel         method access method for pixels outside the boundaries of the image ; ---------------------------------------------------------------------------------- _compare(-metric PSNR rose.jpg, reconstruct.jpg, difference.png) Func _compare ($Option, $Source1, $Source2, $Output="difference.png") ; Code here EndFunc


Than the next functions : convert, composite, mogrify, identify, montage, and stream
And you are done.

Keeps you busy for a while.

Regards,

ptrex

Ahhhhhhh... I see now :) Thanks. I've got some band stuff for like a week, then I can hopefully get this done :)

#15 LOULOU

LOULOU

    loulou

  • Active Members
  • PipPipPipPipPipPip
  • 483 posts

Posted 10 October 2007 - 01:01 PM

Is someone can send me the ImageMagickObject.dll
because i don't know how to made it
Thanks in advance

#16 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 10 October 2007 - 01:33 PM

@Loulou

This is where you download ImageMagick

ImageMagick

Once installed you have the DLL on your system.

Regards

ptrex

#17 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 10 October 2007 - 08:50 PM

How about this for a funky way to call the function?

Using Arrays! YAY!

So Say we had
$aArray[i][0] = Function Name
$aArray[i][1] = Function Parameter

_ImageMagick ("COMPARE", $aArray, $pInput, $pOutput)

I don't know how effective it would be, a downside is it does heavily complicate things... :)

#18 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 11 October 2007 - 06:44 AM

@Bert

Suggestions are always welcome.

Any code that will be posted is better than what I done so far. :)

Regards

ptrex

#19 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 11 October 2007 - 08:47 AM

@Bert

Suggestions are always welcome.

Any code that will be posted is better than what I done so far. :)

Regards

ptrex

Yer. I know... lol.

#20 LOULOU

LOULOU

    loulou

  • Active Members
  • PipPipPipPipPipPip
  • 483 posts

Posted 11 October 2007 - 07:02 PM

How can i do to convert a jpg in gif
example i want to convert 3 files toto.jpeg , toto1.jpeg , toto2.jpeg to toto.gif, toto1.gif,toto2.gif
Is it possible to dop that with a command like that ?
convert *.jpg *.gif
Tha,ks in advance




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users