Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offsets using composite with geometry with gravity #427

Closed
2 tasks done
csalahub opened this issue Apr 17, 2019 · 8 comments
Closed
2 tasks done

Offsets using composite with geometry with gravity #427

csalahub opened this issue Apr 17, 2019 · 8 comments
Milestone

Comments

@csalahub
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET

System Configuration

  • Magick.NET version: (nuget pkg) Magick.NET-Q8-AnyCPU v7.12.0
  • Environment (Operating system, version and so on): Windows 10

Question

I'm trying to place an overlay image of a specific size on a background at a location slightly offset from a gravity position. Is there a way to create a composite image that uses geometry to size and offset an overlaid image from a gravity origin? I've tried the following and the overlaid image is sized and positioned at the gravity location but it is not offset.

const int overlaySizeX = 120;
const int overlaySizeY = 130;
const int overlayOffsetX = -40;
const int overlayOffsetY = 20;
using (var image = new MagickImage(backgroundImage))
{
	var readSettings = new MagickReadSettings { Format = MagickFormat.Png };
	using (var overlay = new MagickImage(foregroundImage, readSettings))
	{
		var geometry = new MagickGeometry(overlayOffsetX, overlayOffsetY, overlaySizeX, overlaySizeY);
		overlay.Resize(geometry);
		image.Composite(overlay, Gravity.North, CompositeOperator.Atop);
		image.Write(output);
	}
}

Here is what I want to do, written in command line requests:

>magick convert -resize 50X35 logo-sm.png logo-smaller.png
>magick composite -gravity center logo-smaller.png -compose atop -geometry -243-167 mountains.jpg cmdOverlaidWizMountains.png

Thanks for your help and for the great library.

@dlemstra
Copy link
Owner

Those commands look like IM6 commands due to their order. Setting .Page on the image might help.

@csalahub
Copy link
Author

Thanks for your response.
The command line is just a demonstration of what I want to do accomplish with your library at the top code box. I read some other issues and questions on stack overflow where you said that you would be able to translate the command lines to c# calls to your library so I figured I'd put the command lines in as a sample.

The command line commands work fine when run against the images provided with the imagemagick installation.
My problem is, in c#, I can't seem to make the geometry offset occur. The overlay is resized but stays at the gravity position.

@dlemstra
Copy link
Owner

dlemstra commented Apr 20, 2019

Yesterday I was on my phone and didn't dig through the code. It turns out that this is not possible yet. It should be very easy to add though. But I don't know when I will publish a new release so it might be a while before this becomes available. When do you need it?

@dlemstra dlemstra added this to the 7.13.0.0 milestone Apr 20, 2019
dlemstra added a commit that referenced this issue Apr 22, 2019
@csalahub
Copy link
Author

csalahub commented May 3, 2019

Brilliant. Thanks so much for the new methods. I'm looking forward to your next release and in the mean time I'll try out the development package.

@csalahub
Copy link
Author

csalahub commented May 9, 2019

Tried out some composite gravity offset tests against your dev package and it works perfectly. Thanks again for the enhancements. We're looking to incorporate the changes as soon as your 7.13.0.0 is released. Any plans or schedule on when this will be? I noticed that previous releases were anywhere between 3-5 weeks apart. Thanks for your help.

@dlemstra
Copy link
Owner

I have not set schedule or plan for doing a new release. Will try to do it this weekend.

@ByronG1987
Copy link

``Hi,
I juste start with this package. And I need you to more information.
I would like to convert this command line
composite.exe -geometry +4+0 test.jpg template_portrait.gif test_final.jpg
To C#

Can you help me please?

Regards

@dlemstra
Copy link
Owner

Could you please start a new discussion @ByronG1987? Please don't hijack an unrelated issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants