Still struggling with composites and transparency

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
squiddy
Posts: 20
Joined: 2018-09-27T02:53:52-07:00
Authentication code: 1152

Still struggling with composites and transparency

Post by squiddy »

ImageMagick 6.9.10-14 Q16 i686 GNU/Linux, 32 bit
Delegates (built-in): bzlib fontconfig freetype jbig jng jpeg lcms lqr lzma pangocairo png tiff wmf x xml zlib

*Still* can't get my head around transparency, backgrounds & foregrounds and compositing ... :?
I'm pretty sure this will turn out to be trivial, so apologies in advance for that.

I want to create images which take as their input any old jpg or png I have to hand, and create as an output an image that "looks like a postage stamp" - i.e. has the scalloped edges characteristic of perforation.
This image will then be composited onto another image (that of an envelope or postcard); there will be a variety of envelope/postcard images, each with different base colours and textures.

The critical thing is to have the perforated edges show the colour/texture of the image "beneath".

I've got myself a "postage stamp template" as a png, and I can manage to do this

Code: Select all

 # convert  example_image.png  stamp_template.png  -transparent  white  -composite  -resize 20%  example_output.png
 
But I can't work out how to make the step to the final image with the output from the above composited onto the envelope.

I've posted all of the files to imagebin:

example_image.png --> https://imagebin.ca/v/4fM6iVyF0vPJ
stamp_template.png --> https://imagebin.ca/v/4fM78Qe26DdV
example_output.png --> https://imagebin.ca/v/4fMDj7dXjU30
example_background --> https://imagebin.ca/v/4fMDvbwBp6R0

I'm sorry if this is unclear in any way.

snibgo
Posts: 12899
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Still struggling with composites and transparency

Post by snibgo »

The images you link to seem to be JPG, not PNG. Perhaps the hosting site does this. I suggest you zip your files together, and paste a link to that zip file.
snibgo's IM pages: im.snibgo.com

squiddy
Posts: 20
Joined: 2018-09-27T02:53:52-07:00
Authentication code: 1152

Re: Still struggling with composites and transparency

Post by squiddy »

I've just downloaded them from imagebin to check, and they are pngs: identify sees them as pngs, and the first three bytes of each are "PNG"

Maybe there's something your browser is doing?

snibgo
Posts: 12899
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Still struggling with composites and transparency

Post by snibgo »

I can't find a download button, with MS Internet Explorer, or Firefox. When I right-click the images, they are JPG.
snibgo's IM pages: im.snibgo.com

squiddy
Posts: 20
Joined: 2018-09-27T02:53:52-07:00
Authentication code: 1152

Re: Still struggling with composites and transparency

Post by squiddy »

weird.
i rightclick and save and they come down as pngs

here's a filebin link for a zipfile: https://filebin.net/uwmxh83aejt8v1l0

snibgo
Posts: 12899
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Still struggling with composites and transparency

Post by snibgo »

Okay, that's fine. I would do it like this. Windows BAT script. For bash, change ^ to \ .

Code: Select all

convert ^
  example_image.png ^
  ( stamp_template.png -resize "960x1280^!" ) ^
  -compose CopyOpacity -composite ^
  -resize 100x100 ^
  example_back.png ^
  +swap ^
  -gravity NorthEast ^
  -compose Over -composite ^
  stamp_out.png
Image
stamp_template isn't the same size as example_image, so I've resized the stamp.

The result is larger than the background, so I've resized it to fit in a 100x100 box. If you don't want it all the way top-right, insert "-geometry +10+10" or whatever before "-compose Over -composite".
snibgo's IM pages: im.snibgo.com

squiddy
Posts: 20
Joined: 2018-09-27T02:53:52-07:00
Authentication code: 1152

Re: Still struggling with composites and transparency

Post by squiddy »

Ah that's perfect!
I'll be resizing everything on the fly anyway (it's for another bot to generate 'random' postcard images).
One day this stuff will have sunk in enough that I don't have to ask, but I expect the planet will have burned to a crisp by then anyway.

thanks so much.

Post Reply