Page 1 of 1

Still struggling with composites and transparency

Posted: 2019-04-29T03:45:13-07:00
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.

Re: Still struggling with composites and transparency

Posted: 2019-04-29T04:24:03-07:00
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.

Re: Still struggling with composites and transparency

Posted: 2019-04-29T11:33:52-07:00
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?

Re: Still struggling with composites and transparency

Posted: 2019-04-29T12:52:44-07:00
by snibgo
I can't find a download button, with MS Internet Explorer, or Firefox. When I right-click the images, they are JPG.

Re: Still struggling with composites and transparency

Posted: 2019-04-30T08:20:22-07:00
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

Re: Still struggling with composites and transparency

Posted: 2019-04-30T09:10:24-07:00
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".

Re: Still struggling with composites and transparency

Posted: 2019-04-30T10:29:56-07:00
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.