Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Using ImageMagick COM object

Closed Thread
 
Thread Tools Display Modes
Old 04-12-2008   #1 (permalink)
Algirdas
Guest
 
Posts: n/a

Using ImageMagick COM object

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..?

 
Old 04-14-2008   #2 (permalink)
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Using ImageMagick COM object

Algirdas wrote:
Quote:

> 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:
http://marcoshaw.blogspot.com
 
Old 04-14-2008   #3 (permalink)
Algirdas
Guest
 
Posts: n/a

Re: Using ImageMagick COM object

Quote:

> 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..
Quote:

> 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.
Quote:

> 2. Try using ImageMagick's .NET assembly from PowerShell.
I wasn't even aware such existed! I'll try to read about it.
 
Old 04-14-2008   #4 (permalink)
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Using ImageMagick COM object

Quote:
Quote:

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

Marco
 
 
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare-Object and Get the name of object/File? akcorr PowerShell 5 06-19-2008 05:15 AM
Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]' Michel Posseth [MCP] .NET General 2 03-27-2008 10:04 AM
Testing object arrays using Compare-Object and -contains Alex K. Angelopoulos [MVP] PowerShell 2 08-31-2006 05:57 PM
Adding canonical aliases for Compare-Object, Measure-Object, New-Object Alex K. Angelopoulos [MVP] PowerShell 2 05-26-2006 07:58 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49