Jump to content

Recommended Posts

Posted (edited)

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.

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
Posted

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

Posted

@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

Posted (edited)

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
  • 4 weeks later...
Posted

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
EndfuncoÝ÷ Ø  Ý¢Ø^­ì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

  • 1 month later...
Posted

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

  • 3 weeks later...
Posted

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.

Posted (edited)

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
Posted

@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
Posted

; ----------------------------------------------------------------------------
; 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

Posted

; ----------------------------------------------------------------------------
; 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 :)
  • 2 weeks later...
Posted

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

Using Arrays! YAY!

So Say we had

$aArray[0] = Function Name

$aArray[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... :)

Posted
Posted

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

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
  • Recently Browsing   0 members

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