Groups > Microsoft > Windows PowerShell > Re: Using ImageMagick COM object




Using ImageMagick COM object

Using ImageMagick COM object
Sat, 12 Apr 2008 08:28:00 -070
Hello,

i have hard time getting ImageMagick COM control to work in powershell 
script. It works fine in VBScript.

here is what I try:

$img = New-Object -ComObject ImageMagickObject.MagickImage
$msgs = $img.Convert("DSC_0205.JPG",  "-resize",
"1024x1024", 
"DSC_0205_out.JPG")

This complains, that "Cannot find an overload for "Convert" and
the argument 
count: "4"."

So I try:

$params = @("DSC_0205.JPG",  "-resize",
"1024x1024", "DSC_0205_out.JPG")
$params
$msgs = $img.Convert($params)

And this says, that: "Argument: '1' should be a 
System.Management.Automation.PSReference. Please use [ref]."

So I try:

$msgs = $img.Convert([ref]$params)

and now all i get it same output as when i run convert.exe without any 
parameters - the default help text. and, of course, no file converted.

What am i doing wrong here..?:(
Post Reply
Re: Using ImageMagick COM object
Mon, 14 Apr 2008 09:32:18 -030
Algirdas wrote:
> Hello,
> 
> i have hard time getting ImageMagick COM control to work in powershell 
> script. It works fine in VBScript.
> 
> here is what I try:
> 
> $img = New-Object -ComObject ImageMagickObject.MagickImage
> $msgs = $img.Convert("DSC_0205.JPG",  "-resize",
"1024x1024", 
> "DSC_0205_out.JPG")
> 
> This complains, that "Cannot find an overload for "Convert"
and the argument 
> count: "4"."

It looks bad when I can't even create a new object that can't be passed 
to get-member:

PSH>$img|get-member
An exception was thrown when trying to enumerate the collection: "Object 
reference not set to an instance of an object.
".
At line:1 char:5
+ $img <<<<

Now, PowerShell's COM implementation has some issues.  I would try:
1. You could call VBScript code form PowerShell, but that defeats the 
purpose in most cases.
-or-
2. Try using ImageMagick's .NET assembly from PowerShell.

Marco


-- 
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
Post Reply
Re: Using ImageMagick COM object
Mon, 14 Apr 2008 10:02:28 -070
> It looks bad when I can't even create a new object that can't be passed 
> to get-member:
> 
> PSH>$img|get-member
> An exception was thrown when trying to enumerate the collection:
"Object 
> reference not set to an instance of an object.
> ".
> At line:1 char:5
> + $img <<<<

Yeah, that's what i had too! I just thought i'm doing something wrong..

> Now, PowerShell's COM implementation has some issues.  I would try:
> 1. You could call VBScript code form PowerShell, but that defeats the 
> purpose in most cases.

It does - i might aswell call it from command line then (which i'm doing 
now). Just wanted to make it more slick.

> 2. Try using ImageMagick's .NET assembly from PowerShell.

Post Reply
Re: Using ImageMagick COM object
Mon, 14 Apr 2008 14:17:03 -030
>> 2. Try using ImageMagick's .NET assembly from PowerShell.
> 
> I wasn't even aware such existed! I'll try to read about it.

http://midimick.com/magicknet/

It seems pretty immature...  A pre-compiled DLL doesn't seem to be provided.

I provided the information without actually reading all the details...

Post Reply
Re: Using ImageMagick COM object
Tue, 15 Apr 2008 17:57:02 -070
Unlike the PerlMagick interface, the ImageMagick COM component is
pretty lame anyway -- it simply provides methods that you can call
that do exactly the same thing as the command-line tools (in fact, the
methods basically take a string array of args  (like the C# "params")
and parses them the same as the command-line arguments.  It was only
provided as a way to avoid having to pop up a console window when
you're running something like a vbscript in WScript which has no
console.

Quite frankly, since in PowerShell you're already at the command-line,
you're better off using the command-line interface... unless you could
Post Reply
about | contact