We're trying to achieve building a custom social sharing image from our app. The backend is built using Ruby/Sinatra and we already use MiniMagick+AWS-SDK to upload user images.
What we want to do is take the user's image and add a stock overlay (it contains a white circle as the placeholder for the variable user image) on top of the user image. I tried using MiniMagick's built-in composite
method using Over
as the operator, but the problem with Over
is, if the overlay is larger than the source, it automatically adjusts according to the source's size. Our overlay is larger and we want to retain the overlay such that the resulting image has the complete overlay with the part of the user image that fits the placeholder white circle visible underneath.
I tried How to use Imagick to merge and mask images? but it doesn't solve my problem.
Basically, say this is the overlay.
And take this sample user image as example:
https://s-media-cache-ak0.pinimg.com/564x/71/08/b5/7108b5a89ce3d6cc0341f876681f8546.jpg
I would like the resulting image to be the complete overlay with the user image visible behind one of those while circles.
Update
As per Mark'sanswer, I wrote the following Ruby code to achieve the result:
avatar = avatar.resize "200x200"
result = mask.composite(avatar) do |c|
c.compose "DstOver"
c.geometry "+100+120" #this could be different depending on your mask's dimensions
end
You can test the result by executing result.write "result.jpg"
Not too sure what you are doing as your mask is an opaque JPEG? However, I think you mean to use a transparent PNG for the mask with a hole in it, in which case you could do this:
convert mask.png \( avatar.jpg -resize 200x200 \) -geometry +360+150 -compose dst-over -composite result.jpg