Page 1 of 1

get verbose return using com object and .net

Posted: 2017-09-22T12:04:38-07:00
by jmaeding
I have been using C# (on windows) to run the imagemagick com object for years now, and it works so well.
Recently, I needed to know how much the virtual canvas "expanded" when I did a 4 point affine distort.
The easy answer is to add -verbose and look at the output.

That works fine when testing in dos window, but it seems the output when using c# is not the same.
The typical code in c# to run the IM object is:
ImageMagickObject.MagickImage img = new ImageMagickObject.MagickImage();
DoProgress("Rubbersheeting...");
object ret1 = img.Convert(allargs.ToArray());

that ret1 variable will be a string with verbose values comma delimited.
Its only giving me like "3456,2446,PNG" though, not what I need.

I know how to use the .Identify method of imobject to get image info, and that works when I need it.
In this case though, I need to get virtual canvas info out at the same time I do the distort, as I +repage the image in that distort sequence.

I do not want to:
1) convert distort without +repage
2) identify to get canvas props
3) run convert again to repage the image.

Getting the canvas info out in one step is the goal, and it seems the .convert method does not capture it in the return variable.
Any ideas?

Re: get verbose return using com object and .net

Posted: 2017-09-22T12:06:21-07:00
by jmaeding
shoot, ignore the:
DoProgress("Rubbersheeting...");
code, that is my progress bar thing, not related to IM com object.

Re: get verbose return using com object and .net

Posted: 2017-09-22T12:24:55-07:00
by snibgo
You don't say what is in allargs.ToArray(), so it's difficult to comment. I suppose it is a list of operations, including "+repage", but it also writes text which you capture.

You can probably include "+write info" in that array, before "+repage".

Re: get verbose return using com object and .net

Posted: 2017-09-22T14:48:11-07:00
by jmaeding
ok, so I did some experiments, I think we are close.
The good thing I found is -write info: does seem to affect the return string from IM com object, but I hit a catch...

My test code is like this for windows dos batch:
"magick.exe" ^
( "C:\Users\james\Desktop\Kir\granite.png" ^
-alpha set -virtual-pixel white +distort Affine "0,0 0,0 128,0 128,0 128,128 200,128" -format "%%H,%%W,%%X,%%Y" -write info:) ^
-compose over -layers merge +repage ^
"C:\Users\james\Desktop\Kir\Final.jpg"

When I run that, I get the canvas dims before the +repage, thought I had it.
When I do the same thing in .net, using the imagemagick com object, it gives 0,0,+0,+0, which is the info after the +repage, not before.

So I wonder if I can tell info: to go to something.
If I try info:c:\temp\info.txt in .net, it works! I get the canvas before +repage. That is a huge step forward as I can read the txt file from .net.
But I wonder if there is some keyword with info: to tell it to send to the object return value, to avoid this external file reading.

Its more a matter of cleanliness than speed at this point.

Re: get verbose return using com object and .net

Posted: 2017-09-22T14:50:13-07:00
by jmaeding
btw, this likely is the same code with just one layer involved:
"magick.exe" ^
"C:\Users\james\Desktop\Kir\granite.png" ^
-alpha set -virtual-pixel white +distort Affine "0,0 0,0 128,0 128,0 128,128 200,128" -format "%%H,%%W,%%X,%%Y" -write info: ^
+repage ^
"C:\Users\james\Desktop\Kir\Final.jpg"