Rotate/Crop Image Layer over Image

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
plempe
Posts: 3
Joined: 2018-04-01T05:15:19-07:00
Authentication code: 1152

Rotate/Crop Image Layer over Image

Post by plempe »

Hey ya'll,

Given are 2 Images:
- (a) Background Image: https://i.imgur.com/dZGoHko.png
- (b) Image to overlay on the backgrorund image: https://i.imgur.com/We5n1Cj.png

I want to overlay Image (b) on top of Image (a). I also have given position info with roatation angle on where to put the Image (b) on (a).
Lets go with this position numbers:
- top: 40px
- left: 200px
- width: 40px
- height: 100px
- angle: 45°

So the result should look like this: https://i.imgur.com/fOlxg6Y.png

Currently i have this command:

Code: Select all

convert background.png -draw "rotate 45 image Over 200,40 40,100 overlay.png" test.png
With this command i get this unexcpected result: https://i.imgur.com/m0XqyAb.png
I think the problem is the gravity of the overlayed image. I dont want it to be rotated fom the top left corner.
It should be rotated from the center of the overlayed image position.

Any tips?

Also how could i crop the overlayed image before putting it on top of the background?

Thanks in advance!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Rotate/Crop Image Layer over Image

Post by snibgo »

plempe wrote:Lets go with this position numbers:
- top: 40px
- left: 200px
This might mean either:
1. The original top-left corner of the overlay should move to (200,40) in the result, or
2. The top-left corner of the image formed by the rotated overlay should move to (200,40) in the result.

However, your desired result is neither of these.

Can you explain how you got your desired result?
snibgo's IM pages: im.snibgo.com
plempe
Posts: 3
Joined: 2018-04-01T05:15:19-07:00
Authentication code: 1152

Re: Rotate/Crop Image Layer over Image

Post by plempe »

snibgo wrote: 2018-04-01T06:27:54-07:00
plempe wrote:Lets go with this position numbers:
- top: 40px
- left: 200px
This might mean either:
1. The original top-left corner of the overlay should move to (200,40) in the result, or
2. The top-left corner of the image formed by the rotated overlay should move to (200,40) in the result.

However, your desired result is neither of these.

Can you explain how you got your desired result?
Oh sorry i do have forgotten to mention that.
I do mean like you said on your point 2. that i want the top left corner to move at 200,40 in the result. https://i.imgur.com/qFN8WOx.png

I made my desired image in paint, its just roughly made without exact position and rotation.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Rotate/Crop Image Layer over Image

Post by snibgo »

I would do it like this (Windows syntax):

Code: Select all

convert dZGoHko.png ( We5n1Cj.png -virtual-pixel None +distort SRT 0,0,1,45,0,0 -repage "+200+40^!" ) -compose Over -layers merge out.png
snibgo's IM pages: im.snibgo.com
plempe
Posts: 3
Joined: 2018-04-01T05:15:19-07:00
Authentication code: 1152

Re: Rotate/Crop Image Layer over Image

Post by plempe »

@snibgo Thank you vey much!
Post Reply