Page 1 of 1
Is these code equal with the commad?
Posted: 2008-11-29T17:39:41-07:00
by smileface
Code: Select all
//read a image src.jpg to handler magick_wand
MagickSetImageMatte(magick_wand,MagickTrue);
MagickSetImageProperty(magick_wand,"virtual-pixel","transparent");
...
MagickDistortImage(magick_wand,AffineProjectionDistortion,6,doubleArray,MagickFalse);
MagickWriteImage(magick_wand,"out.png");
Are they equal with command:
convert src.jpg -matte -virtual-pixel transparent -distort '0.9,0.1,0.1,0.9,0,0' out.png
and i wonder what ( i mean the code) the command option like "-virtual-pixel transparent" etc equal to?
Re: Is these code equal with the commad?
Posted: 2008-11-29T17:51:47-07:00
by magick
Use MagickSetImageVirtualPixelMethod() to set the virtual method.
Re: Is these code equal with the commad?
Posted: 2008-11-29T18:26:00-07:00
by smileface
Code: Select all
//read a image src.jpg to handler magick_wand
...
MagickSetImageMatte(magick_wand,MagickTrue);
MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod);
...
MagickDistortImage(magick_wand,AffineProjectionDistortion,6,doubleArray,MagickFalse);
//want to get a transparent background PNG file
MagickWriteImage(magick_wand,"out.png");
i try like this,but the question remain,after function MagickDistortImage called(do affineTransform),i still can not get a tranparent background png file.
but if i use command line that it works well.it is so crazy,i felt.
Re: Is these code equal with the commad?
Posted: 2008-11-29T18:41:53-07:00
by el_supremo
I posted about a similar problem in
viewtopic.php?f=1&t=12575
It turns out there's a bug somewhere in the distort itself. I will post to the bugs forum soon.
Pete
Re: Is these code equal with the commad?
Posted: 2008-11-29T19:00:33-07:00
by smileface
before i post this topic, i have already saw your reply
viewtopic.php?f=1&t=12575 and read your code,then i copy your code to try.may be that your writen
Code: Select all
MagickSetImageProperty(mw,"virtual-pixel","transparent");
is not correct.u could use this function just like magick reply.
Code: Select all
MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod);
at last i want to say:even i use
Code: Select all
MagickSetImageAlphaChannel(magick_wand,SetAlphaChannel);
MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod);
or
Code: Select all
MagickSetImageMatte(magick_wand,MagickTrue);
MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod);
both of them failed.who know how to do?i need the solution (code) equal to using command line:
convert src.jpg -matte -virtual-pixel transparent -distort '0.9,0.1,0.1,0.9,0,0' out.png
Re: Is these code equal with the commad?
Posted: 2008-11-29T19:09:06-07:00
by el_supremo
No it's not a bug in IM. But I can't figure out how to replicate a command line which uses distort. I get a rather odd result depending on the input image.
When the input file to the program below has an alpha channel *and* the edges of the image are themselves transparent, like this
http://members.shaw.ca/el.supremo/logo_paintflood.png, the virtual pixel method works. But if I paint around the edge of the image with white and then use that as input (e.g. this
http://members.shaw.ca/el.supremo/logo_distort_pf.png), the virtual pixel method fails. In both cases, the equivalent command line works so there must be some sort of default action hidden within the convert command.
Pete
Code: Select all
#include <windows.h>
#include <wand/magick_wand.h>
void test_wand(LPTSTR lpCmdLine)
{
MagickWand *mw = NULL;
double cpoints[16] = {
7,40, 4,30, 4,124, 4,123, 85,122, 100,123, 85,2, 100,30
};
MagickWandGenesis();
mw = NewMagickWand();
MagickReadImage(mw,"logo_distort_pf.png");
// -matte is the same as -alpha on
MagickSetImageAlphaChannel(mw,SetAlphaChannel);
/*
For a list of valid virtual pixel methods in your version of IM
use the command:
convert -list virtualpixel
*/
MagickSetImageVirtualPixelMethod(mw,TransparentVirtualPixelMethod);
// and then apply the result to the image
MagickDistortImage(mw,PerspectiveDistortion,
16,(const double *)&cpoints,MagickFalse);
MagickWriteImage(mw,"logo_distort_p.png");
/* Clean up */
if(mw)mw = DestroyMagickWand(mw);
MagickWandTerminus();
}
Re: Is these code equal with the commad?
Posted: 2008-11-29T19:28:55-07:00
by smileface
If the input file to the program is png file,it is not necessary to call extra function to set.
And default case, I found the function MagickDistortImage do affineTransform well.
but if the input file to the program is jpeg file,that is the problem,just like pete said may be some function were called hidden when u using the command,though we could know 2 functions may be called only.what is more?I'm hoping that magick will tell us what we're missing too.
Re: Is these code equal with the commad?
Posted: 2008-11-30T13:49:57-07:00
by smileface
by version 6.4.6-7 ,finally i found the way,and it works well for png,gif,and jpeg image file.
I get it!
Re: Is these code equal with the commad?
Posted: 2008-11-30T14:06:32-07:00
by magick
If the developers only had 5 minutes of free time-- we always had in mind an option to generate a source module that replicates the command line, for example
- convert -background lightblue -fill blue \
-font Candice -pointsize 72 label:Anthony \
-c label.c label.gif
would produce a ready-to-compile MagickWand source module called label.c that produces the same results as the command line.
Re: Is these code equal with the commad?
Posted: 2008-11-30T22:56:24-07:00
by anthony
That as well as a more 'function' orientated "convert" command is something to keep in mind in my proposed re-write to allow "convert" to read operations from files or streams.
A 'function' orientation wold also help with a 'fake' "mogrify" type replacement too.
My thinking of this is coalescing but I may need to look at better option to token parsing to make this work properly. I am a little out of date with parsers (yacc, bison, etc) at the moment. It is now 20 since I did my compiler design work after all!