Page 1 of 1

How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T02:44:02-07:00
by Airon65
My code is:

Code: Select all

Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( QuantumRange, QuantumRange, QuantumRange, QuantumRange ) );

std::vector < Magick::Drawable > objArr;

double dash_array_8stroke_8fill[] = { 8, 8, 0 };
objArr.push_back( Magick::DrawableStrokeDashArray( dash_array_8stroke_8fill ) );
	
objArr.push_back( Magick::DrawableRotation( 45 ) );

objArr.push_back( Magick::DrawableStrokeWidth( 5 ) );
objArr.push_back( Magick::DrawableStrokeColor( "red" ) );
objArr.push_back( Magick::DrawableFillColor( "green" ) );
objArr.push_back( Magick::DrawableRectangle( 100, 100, 370, 370 ) );

objArr.push_back( Magick::DrawableRotation( 75 ) );
objArr.push_back( Magick::DrawableCompositeImage( 100, 100, "images/img.jpg" ) );
objArr.push_back( Magick::DrawableRotation( 75 ) );

testImg.draw( objArr );
I have rotated rectangle only. My image in this case is not rotated but why?

Version: ImageMagick 7.0.5-2 Q16 x86_64 2017-03-11

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T02:47:37-07:00
by Airon65
If I do something like this:

Code: Select all

Magick::Image horseImg( "images/horse.jpg" );
horseImg.rotate( 75 );

Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( QuantumRange, QuantumRange, QuantumRange, QuantumRange ) );

std::vector < Magick::Drawable > objArr;

double dash_array_8stroke_8fill[] = { 8, 8, 0 };
objArr.push_back( Magick::DrawableStrokeDashArray( dash_array_8stroke_8fill ) );

objArr.push_back( Magick::DrawableRotation( 45 ) );

objArr.push_back( Magick::DrawableStrokeWidth( 5 ) );
objArr.push_back( Magick::DrawableStrokeColor( "red" ) );
objArr.push_back( Magick::DrawableFillColor( "green" ) );
objArr.push_back( Magick::DrawableRectangle( 100, 100, 370, 370 ) );

objArr.push_back( Magick::DrawableCompositeImage( 100, 100, horseImg ) );

testImg.draw( objArr );

I get twice-rotated scene! Is it a bug? I just need to rotate those objects separately...

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T03:05:30-07:00
by snibgo
Airon65 wrote:I have rotated rectangle only. My image in this case is not rotated but why?
See the documentation http://www.imagemagick.org/script/comma ... s.php#draw :
The rotate primitive rotates subsequent shape primitives and text primitives about the origin of the main image.
An image is not a shape primitive, nor a text primitive.
Airon65 wrote:I get twice-rotated scene!
What does that mean? Please show the result.

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T03:52:44-07:00
by Airon65
The first code produces me next result:
Image
The second one is:
Image

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T03:55:50-07:00
by Airon65
snibgo wrote: 2017-04-19T03:05:30-07:00
Airon65 wrote:I get twice-rotated scene!
What does that mean? Please show the result.
It means that the system rotates it once and then seems it rotates it twice

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T04:17:46-07:00
by snibgo
The horse has rotated once, by 75 degrees. That is what you asked for.

I can't see how much the rectangle has rotated.

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T04:22:11-07:00
by Airon65
snibgo wrote: 2017-04-19T04:17:46-07:00 The horse has rotated once, by 75 degrees. That is what you asked for.

I can't see how much the rectangle has rotated.
But why the rectangle has the another place on the second image? I didn't change its coordinates...

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T15:34:39-07:00
by Airon65
Why the rectangle changes its place? Is this normal behaviour or some sort of a bug?

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T15:47:59-07:00
by snibgo
The rotate primitive rotates subsequent shape primitives and text primitives about the origin of the main image.

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T15:51:53-07:00
by fmw42
You are not rotating by a simple one-time 75 degrees. If I do a 75 deg rotate, I get something different and the green and red lines are just fine.

Try this in the command line to test what a 75 degree rotate should look like.

Code: Select all

convert wk3Sup6.png -rotate 75 tmp.png
Your image is rotated by 75 degrees but is being shifted to the left rather than being center rotated. I am not sure why your green and red lines are offset. But I suspect you may be rotating and then overlaying in some way. Sorry, I do not read Magick++ code well. I suggest you test in the command line and when you get that working then convert to Magick++


EDIT: Sorry I misread your code and saw 45 degrees there. But you actually want 75 deg. So I have corrected my comments above.

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T16:28:39-07:00
by Airon65
snibgo wrote: 2017-04-19T15:47:59-07:00 The rotate primitive rotates subsequent shape primitives and text primitives about the origin of the main image.
Well, so can Magick++ rotate object around a specified anchor point of that object?
What's the origin of the main image? Is it the center of it?

Re: How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Posted: 2017-04-19T16:41:44-07:00
by snibgo
The origin of an image is coordinate (0,0), the top-left corner.