Advise please: Join -> Overlay -> Flatten -> Split again ?

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
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

Hello ImageMagick gurus... I need some help please...

I have 4 jpeg images in a base layer as follows:
- 100x100 pixels: top_left.jpg
- 100x100 pixels: top_right.jpg
- 100x100 pixels: bottom_left.jpg
- 100x100 pixels: bottom_right.jpg

I have 2 transparent png's in 2 layers above:
- 200x200 pixels: overlay1.png
- 200x200 pixels: overlay2.png

I want to overlay the 2 transparent png images across the top of the 4 joined jpeg images and save the result as 4 jpegs again. Preferably using a single command with quality options too.

I'm faffing around like a crisp packet in the wind trying to do this. Please help.

I'm using the command line tools on a mac by the way.

Thanks for any help or pointers.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by snibgo »

I don't understand "and save the result as 4 jpegs again". 4 different jpegs? Just different qualities, or showing different things?

Anyhow, it might be something like this, untested, Windows syntax:

Code: Select all

convert ^
  ( top-left.jpg top-right.jpg +append ) ^
  ( bottom-left.jpg bottom-right.jpg +append ) ^
  -append ^
  overlay1.png -composite ^
  overlay2.png -composite ^
  -quality 50 +write out1.jpg ^
  -quality 60 +write out2.jpg ^
  -quality 70 +write out3.jpg ^
  -quality 80 +write out4.jpg ^
  null:
For Unix, use \ instead of ^.
snibgo's IM pages: im.snibgo.com
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

Sorry for the lack of clarity in my question snibgo - actually, output files will need to overwrite the original 4 jpegs.
Thanks very much for giving me the example code - it's taking me a while to get my head around the CLI syntax. I need to go and play with this.

Kind Regards,
Jez
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by snibgo »

If you want to divide the output into 4 equal tiles, "-crop 2x2@" will do that. But I don't see why you want to append images, then chop them up again.
snibgo's IM pages: im.snibgo.com
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

snibgo wrote:If you want to divide the output into 4 equal tiles, "-crop 2x2@" will do that. But I don't see why you want to append images, then chop them up again.
Again, sorry Snibgo for not doing a great job of explaining my problem. Hopefully this will help...

https://www.dropbox.com/s/xxx8ol7yziwrh ... e.png?dl=0

Starting with the four corner png's, I want to overlay 2 bigger png's and save to 4 new corner jpegs.

I'll need to down-sample the overlays too if this is possible in one go?

Is all this possible in one go?

Many thanks.
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

Image

Trying to post an image here to explain my task. Preview not showing, but hopefully posting will show it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by snibgo »

For the lines ...

Code: Select all

  overlay1.png -composite ^
  overlay2.png -composite ^
... you could have ...

Code: Select all

  ( overlay1.png -resize AxB ) -composite ^
  ( overlay2.png -resize CxD ) -composite ^
where A, B, C and D are whatever you need. See http://www.imagemagick.org/script/comma ... php#resize

You could also add shadows, but get the basics working first.
snibgo's IM pages: im.snibgo.com
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

hi snibgo, the following gives me 4 new jpegs which contain the same pixels as overlay2.png

convert \
\( top-left.png top-right.png +append \) \
\( bottom-left.png bottom-right.png +append \) \
-append \
overlay1.png -composite \
overlay2.png -composite \
-quality 50 +write out1.jpg \
-quality 60 +write out2.jpg \
-quality 70 +write out3.jpg \
-quality 80 +write out4.jpg \
null:

Do I need another append somewhere?

I hope this image explains my intention, and yes, I can do drop shadows once I've got the basics...
Image

Many Thanks,
Jez
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by snibgo »

As I said upthread, "-crop 2x2@" will divide the image into 4 equal tiles.

Code: Select all

convert \
\( top-left.png top-right.png +append \) \
\( bottom-left.png bottom-right.png +append \) \
-append \
overlay1.png -composite \
overlay2.png -composite \
-crop 2x2@ ^
-quality 50 +write out_%02.jpg \
null:
This should make out_00.jpg, out_01.jpg etc.

(But don't use JPEGs unless you really have to.)
snibgo's IM pages: im.snibgo.com
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

Very nice - getting real close now! Thanks snibgo!

Is it possible to specify each of the output filenames separately?
Is is possible to scale one of the overlay images as part of this same command?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by snibgo »

For scaling, like I said upthread. See my post starting "For the lines ..."

For specifying four different output names, yes, it can be done in IM, but it's a bit messy (using clone, write, delete). I would rename in the script.
snibgo's IM pages: im.snibgo.com
Jezza
Posts: 7
Joined: 2015-03-03T17:46:53-07:00
Authentication code: 6789

Re: Advise please: Join -> Overlay -> Flatten -> Split again ?

Post by Jezza »

Perfect. Many thanks for your help snibgo - the script and advise above has really helped me.
Post Reply