How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

How to draw rotated image using DrawableCompositeImage and DrawableRotation?

Post 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
Last edited by Airon65 on 2017-04-19T03:53:33-07:00, edited 1 time in total.
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

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

Post 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...
Last edited by Airon65 on 2017-04-19T03:53:49-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

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

Post by Airon65 »

The first code produces me next result:
Image
The second one is:
Image
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

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

Post 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...
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

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

Post by Airon65 »

Why the rectangle changes its place? Is this normal behaviour or some sort of a bug?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

The rotate primitive rotates subsequent shape primitives and text primitives about the origin of the main image.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

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

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

The origin of an image is coordinate (0,0), the top-left corner.
snibgo's IM pages: im.snibgo.com
Post Reply