Page 1 of 1

PNG file manipulation

Posted: 2019-05-20T12:15:15-07:00
by cejones
I need to take a single PNG file, tile it 3x3 and then save it out, preserving the alpha channel.

I have worked my way to the following command:

montage original_file*.png -tile 3x3 -alpha set -geometry +0+0 tiled_file.png

montage sucks because it requires I have 9 identical files in the working directory, so my script generates them and then deletes them after the montage command. I tried to use the convert command in place of montage, which does not require multiple files to tile, but it was not handling the alpha channel properly. (convert -size {$newXresolution}x{$newYresolution} tile:original_file.png tiled_file.png) where the new resolutions are 3X the originals.

This montage command creates what I need, but when I compare the original file to the output file, the alpha channel starts off as 8-bit, but the output file shows it as 1-bit.

Is there a way to tell montage to keep all image parameters the same as the original file... especially the alpha channel settings? I tried saving using the PNG8:, PNG16, etc but this did not help.

Version of IM I am using: Version: ImageMagick 6.9.10-11 Q16 x86_64 2018-09-08

Any help is appreciated,

Chris
Austin, TX

Re: PNG file manipulation

Posted: 2019-05-20T13:24:49-07:00
by fmw42
Why use montage. Just use append. Here is an example

# make transparent image from internal Imagemagick logo:

Code: Select all

convert logo: -transparent white logot.png
# make 3x3 tiling

Code: Select all

convert logot.png -duplicate 2 +append \
\( -clone 0 -clone 0 \) -append \
result.png

Re: PNG file manipulation

Posted: 2019-05-20T14:10:15-07:00
by cejones
Thank you fmw42. This works great. I now need to learn how duplicate, append and clone work so I can understand what this is actually doing

What if I wanted to add X number of pixels between each image... to space them out?

Chris

Re: PNG file manipulation

Posted: 2019-05-20T14:32:44-07:00
by snibgo
cejones wrote:montage sucks because it requires I have 9 identical files in the working directory, ...
Or just one file and "-duplicate 8".
cejones wrote:This montage command creates what I need, but when I compare the original file to the output file, the alpha channel starts off as 8-bit, but the output file shows it as 1-bit.
I suggest you remove "-alpha set" (which is harmless but pointless) and insert "-background None".

Re: PNG file manipulation

Posted: 2019-05-20T14:52:54-07:00
by GeeMack
cejones wrote: 2019-05-20T12:15:15-07:00montage sucks because it requires I have 9 identical files in the working directory, so my script generates them and then deletes them after the montage command.
The other solutions offered above are good. Here's another pretty simple idea to make a 3x3 tiled result from a single input image...

Code: Select all

convert input.png -background none -duplicate 2 +append -duplicate 2 -append result.png

Re: PNG file manipulation

Posted: 2019-05-20T15:13:51-07:00
by cejones
Thank you GeeMack. Yours is a cleaner looking line of code. I tested it and it works well.

And thank you snibgo. I modified my montage code with -duplicate 8 and it indeed removes the need for multiple files. Awesome day... learned how to use duplicate, append and clone.

Thank you all for the help!

Re: PNG file manipulation

Posted: 2019-05-20T15:32:19-07:00
by snibgo
cejones wrote:What if I wanted to add X number of pixels between each image... to space them out?
With GeeMack's "convert" command, you can "-border" immediately after the input.png, or "-extent" or "-splice", perhaps with a final "-chop", depending on the exact effect you want.

Re: PNG file manipulation

Posted: 2019-05-21T06:48:32-07:00
by cejones
-border works great and solves that question. Thank you snibgo. I really like your IM pages... lots of great scripts for me to learn from.