[SOLVED] HowTo 'stamp' Image1 on top Image2 on new Image3

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
msx

[SOLVED] HowTo 'stamp' Image1 on top Image2 on new Image3

Post by msx »

Hi!
This is the situation: I have a PNG with transparent background containing a flyleaf at the bottom of the file and I want to impress it over several other image files; the PNG flyleaf file and all the rest of the other files have the same size. I would like to make a script using Bash -or even Perl with the PerlMagick application- to automate this but I'm having a hard time trying to figure out how to do this with 'convert' application so I'm looking for any feedback you can provide!

branding_file.png
book1_picture.jpg
book2_picture.jpg
...
book25_picture.jpg

The idea is to impress branding_file.png over book*_picture.jpg creating book*_picture_stamped.jpg

Thank you =)
Last edited by msx on 2010-12-02T23:29:25-07:00, edited 1 time in total.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by GreenKoopa »

The -composite command will work for combining images.

An entire page of usage examples:
http://www.imagemagick.org/Usage/compose/

This task should be reasonably easy.
Last edited by GreenKoopa on 2010-11-30T22:18:18-07:00, edited 1 time in total.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by GreenKoopa »

As for your second need, inputting and outputting multiple files, using * or ? works like one would expect.

Usage Examples > Image File Handling
http://www.imagemagick.org/Usage/files/
msx

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by msx »

Thanks! I did a search but didn' find nothing, I'll take a look now =)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by anthony »

You can do this overlay with mogrify, though because of its limitation with handling two images simultaneously, you will need to use -draw to do the image overlay.

See http://www.imagemagick.org/Usage/basics ... fy_compose

As the overlay image is only a corner, it should be posible to use a smaller overlay.
If you can provide a link to the images I can try out and demonstrate an actual command, or posibly figure out a better method.

PS: also see Thumbnails, Double Masking Technique,
http://www.imagemagick.org/Usage/thumbn ... ouble_mask
this is also very appropriate to doing curled corners. I just have not added examples of curled corners as yet.

you amy also like to look at Fred Wienhaus's PageCurl script...
http://www.fmwconcepts.com/imagemagick/ ... /index.php
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
msx

Re: HowTo 'stamp' Image1 on top Image2 on new Image

Post by msx »

@anthony
I _really_ appreciate this! I own a little but well provided second-hand bookshop and I'm trying to build an online catalogue. If you ever saw "Black Books" (WP: http://en.wikipedia.org/wiki/Black_Books YT:[0]) then you know what I'm talking about =)

This is a sample book cover http://www.fileden.com/files/2010/5/7/2 ... ATURA.jpeg and this is the file I want to stamp over it and the other pictures: http://www.fileden.com/files/2010/5/7/2 ... 0LEEyC.png, in the end I should have something like this: http://www.fileden.com/files/2010/5/7/2 ... IATURA.jpg
I already created a template to do this in GIMP but I really want to make this the most automated way it's possible, also I'm a CLI junkie so I enjoy creating scripts to handle these things.

I must point I'm not scared of RTFM, I'm just short of time these days. Anyway, I was to do that when I found your kind help offer.
Greetings,
Martin

[0]
http://www.youtube.com/watch?v=Kpr-JunXMkM
http://www.youtube.com/watch?v=VQ74p_XS ... re=related
http://www.youtube.com/watch?v=OMXdziu8FBk
Last edited by msx on 2010-12-02T23:29:46-07:00, edited 4 times in total.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by GreenKoopa »

The solution in my head seemingly differs from Anthony's, but here is my try:

convert book*_picture.jpg null: branding_file.png -layers composite book%%d_picture_stamped.jpg
msx

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by msx »

@GreenKoopa
HAHA, that was BRILLIANT! Thank you very much for that, sure I owe you guys some cold beers! :D:D:D
Now I can finish my script to automate batch process: rotate, resize and thumbnail creation of books covers.

I'm a Free Software advocate and FLOSS supporter and in line with my way I will donate to ImageMagic once the eshop is rolling. I strongly believe one should support freely available, useful and excellent software as ImageMagic is, in this case backed by a great community.

Once again, thank you *very* much.
Best,
Martin
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: [SOLVED] HowTo 'stamp' Image1 on top Image2 on new Image

Post by GreenKoopa »

I'm only a new user myself, but I'm sure they would appreciate your support. They certainly deserve some.

I didn't test my proposed solution so please let us know if it somehow doesn't meet your needs. I have done much combining of images, but I only work with one at a time and so have never tried the same operation across a collection of images like you need.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by anthony »

GreenKoopa wrote:The solution in my head seemingly differs from Anthony's, but here is my try:

convert book*_picture.jpg null: branding_file.png -layers composite book%%d_picture_stamped.jpg
Slight variation that will handle any image name, and just prefix 'stamped_' to the result
That can also be a path to a different directory!

Code: Select all

convert book*_picture.jpg -set filename:original %f \
            null: branding_file.png -layers composite \
            +adjoin stamped_%[filename:original]
See IM Examples, Filename Percent Escapes
http://www.imagemagick.org/Usage/files/#save_escapes
I was amazed it works so well!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: HowTo 'stamp' Image1 on top Image2 on new Image3

Post by anthony »

anthony wrote:
GreenKoopa wrote:The solution in my head seemingly differs from Anthony's, but here is my try:

convert book*_picture.jpg null: branding_file.png -layers composite book%%d_picture_stamped.jpg
Slight variation that will handle any image name, and just prefix 'stamped_' to the result
That can also be a path to a different directory!

Code: Select all

convert book*_picture.jpg -set filename:original %f \
            null: branding_file.png -layers composite \
            +adjoin stamped_%[filename:original]
See IM Examples, Filename Percent Escapes
http://www.imagemagick.org/Usage/files/#save_escapes
I was amazed it works so well!
One word of warning about using convert. It reads ALL the images into memory first.
If the images are large, then you may run out of memory.

Using mogrify will only read one filename at a time, and thus uses far less memory.
However as mentioned you are limited to using -draw to do the image composition
http://www.imagemagick.org/Usage/basics ... fy_compose
Basically as "mogrify" is limited to using "Simple Image Processing Operators"
http://www.imagemagick.org/Usage/basics/#option_simple
That excludes multi-image sequence operators such as -composite, and -layers
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply