Is these code equal with the commad?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
smileface

Is these code equal with the commad?

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Is these code equal with the commad?

Post by magick »

Use MagickSetImageVirtualPixelMethod() to set the virtual method.
smileface

Re: Is these code equal with the commad?

Post 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.
Last edited by smileface on 2008-11-29T18:42:32-07:00, edited 1 time in total.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Is these code equal with the commad?

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
smileface

Re: Is these code equal with the commad?

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Is these code equal with the commad?

Post 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();
}
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
smileface

Re: Is these code equal with the commad?

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

Re: Is these code equal with the commad?

Post 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!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Is these code equal with the commad?

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is these code equal with the commad?

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply