Best way to stack and color multiple images?
Best way to stack and color multiple images?
In the past I have used Illustrator to create icons. Each icon on it's own artboard. To change colors I simply select all of the same color, change it, this applies to all the icons and then I export the artboards to pngs.
What I'd like to do is come up with a way to script this, as well as add in some variables. For example, to make 1 single icon, there are 6 layers, 3 circular lines and 2 gradients and 1 image that sit centered on top of each other. I though I could stack them with composite -geometry center, but that seems to only allow for 2 images at a time, so I'm assuming rather than making 9 lines of composite, there has to be a better way to stack them.
At the same time, I am hoping that I could have the files saved as grayscale SVGs or PNGs so that I could do some type of color overlay or colorization of the layers.
So the methodology would be something like: stack center images 1, 2 and 3 [then] stack and color image 4 with a blue and white gradient [then] stack images 5 and 6 on top that centered.
What is the best way to go about this?
Also, if I put the script into a bash file, would I be able to add variables, like instead of specifying "color this purple" I could put something like "color this $1" and then when I run the script I can assign $1=purple or blue or whatever? Does that make sense?
What I'd like to do is come up with a way to script this, as well as add in some variables. For example, to make 1 single icon, there are 6 layers, 3 circular lines and 2 gradients and 1 image that sit centered on top of each other. I though I could stack them with composite -geometry center, but that seems to only allow for 2 images at a time, so I'm assuming rather than making 9 lines of composite, there has to be a better way to stack them.
At the same time, I am hoping that I could have the files saved as grayscale SVGs or PNGs so that I could do some type of color overlay or colorization of the layers.
So the methodology would be something like: stack center images 1, 2 and 3 [then] stack and color image 4 with a blue and white gradient [then] stack images 5 and 6 on top that centered.
What is the best way to go about this?
Also, if I put the script into a bash file, would I be able to add variables, like instead of specifying "color this purple" I could put something like "color this $1" and then when I run the script I can assign $1=purple or blue or whatever? Does that make sense?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Best way to stack and color multiple images?
to composite multiple images, use convert ... -flatten see http://www.imagemagick.org/Usage/layers/
I am not sure I follow all your steps. Perhaps you could post a link to some examples of the components and the final product.
PNGs could created with IM for output. Don't know much about SVGs.
Colors can be changed in a number of ways in IM. For example using -fuzz XX% -fill newcolor -opaque oldcolor. Also one can convert to grayscale and then colorize with +level-colors black,newcolor. See http://www.imagemagick.org/Usage/color_basics/#replace and http://www.imagemagick.org/Usage/color_ ... vel-colors
Variables can be used in bash scripts to do what I think you want to parameterize. You could look over some of my bash scripts below.
I am not sure I follow all your steps. Perhaps you could post a link to some examples of the components and the final product.
PNGs could created with IM for output. Don't know much about SVGs.
Colors can be changed in a number of ways in IM. For example using -fuzz XX% -fill newcolor -opaque oldcolor. Also one can convert to grayscale and then colorize with +level-colors black,newcolor. See http://www.imagemagick.org/Usage/color_basics/#replace and http://www.imagemagick.org/Usage/color_ ... vel-colors
Variables can be used in bash scripts to do what I think you want to parameterize. You could look over some of my bash scripts below.
Last edited by fmw42 on 2011-04-25T16:51:48-07:00, edited 1 time in total.
Re: Best way to stack and color multiple images?
Thanks Fred, your website actually came up in a google search I was doing earlier for IM scripts
I'm still a bit confused with the layer, just because composite doesn't seem like the most appropriate command for handling multiple images, but if that's the only way to do it I guess I'm stuck making lots of intermediate images...To clarify my question a bit better. I make icons that look like this
That image is composed of these images stacked on top of each other (and centered):
I was hoping to be able to stack these images on top of each other without having to create an intermediate output file, or temp file, or whatever the terminology would be. Since when I look at the composite command it looks to me like I"d have to combine images 1 and 2 to make X, then take X add 3 to make Y, take Y add 4, etc... Unless I'm reading the commands on that page wrong?
I'm still a bit confused with the layer, just because composite doesn't seem like the most appropriate command for handling multiple images, but if that's the only way to do it I guess I'm stuck making lots of intermediate images...To clarify my question a bit better. I make icons that look like this
That image is composed of these images stacked on top of each other (and centered):
I was hoping to be able to stack these images on top of each other without having to create an intermediate output file, or temp file, or whatever the terminology would be. Since when I look at the composite command it looks to me like I"d have to combine images 1 and 2 to make X, then take X add 3 to make Y, take Y add 4, etc... Unless I'm reading the commands on that page wrong?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Best way to stack and color multiple images?
You can do things in pairs and chain them with convert without creating intermediate saved images.I was hoping to be able to stack these images on top of each other without having to create an intermediate output file, or temp file, or whatever the terminology would be. Since when I look at the composite command it looks to me like I"d have to combine images 1 and 2 to make X, then take X add 3 to make Y, take Y add 4, etc... Unless I'm reading the commands on that page wrong?
convert image1 image2 -compose... -composite image3 -compose ... -composite etc result
see http://www.imagemagick.org/Usage/layers/#convert
IM allows you to process multiple converts in one convert using parenthesis and clones. So you can specify each image in the convert and put the one that needs to be colored inside parens with the commands you need for it, then in the same convert specify the positioning for each using -page, if they are not all the same size, and use -flatten to combine them. Which image gets the blue color? For example, assuming they are the same size and image 5 is to be colored blue, then something like
convert image1 image2 image3 image4 \( image5 -fill blue -colorize 100% \) image6 -flatten result
If you need processing and different compose methods for each pair, then one can still do multiple convert ... -composite in pairs (as above) in the same command line, using parenthesis if needed for the other processing. One needs to use convert and not composite to do all of this. Composite is very limited, but convert ... -compose ... -composite is more flexible. With convert ... -composite, you position using either or both -gravity and -geometry rather than -page as in flatten.
If you can tell me what steps you use to combine each of your images, then, perhaps I can specify an equivalent command line. Otherwise, see
http://www.imagemagick.org/Usage/basics/#image_seq and the sections that follow.
Re: Best way to stack and color multiple images?
Thanks, so if I understand this right, then the proper syntax for making those grayscale images into the blue icon above would be this:
I put spacing to see the commands for each image. I'd try this right now, but at the moment I'm not in front of my computer.
Ideally, I'd want to place that in a file and then run it as a script like "bash IMstack" or whatever I decide to call it.
Code: Select all
convert -size 48x48 \
1-outerring.png -fill gray -colorize 100% \
1-outerring.png -geometry center -composite \
2-backgroundgradient.png -fill gray -colorize 100% \
2-backgroundgradient.png -geometry center -composite \
3-gradient.png -fill blue -colorize 100% \
3-gradient.png -geometry center -composite \
4-outerring.png -fill blue -colorize 100% \
4-outerring.png -geometry center -composite \
5-innergradient.png -fill blue -colorize 100% \
5-innergradient.png -geometry center -composite \
bikeicon.png -fill white -colorize 100% \
bikeicon.png -geometry center -composite \
finalbikeicon.gif
Ideally, I'd want to place that in a file and then run it as a script like "bash IMstack" or whatever I decide to call it.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Best way to stack and color multiple images?
Not quite right. Here is the best I can do with your commands in the proper syntax. However, just compositing one over the other will not give your results unless there is some transparency somewhere. Otherwise, you need to use different compose methods. see http://www.imagemagick.org/Usage/compose/
That is why I asked for the actual processing steps you have used elsewhere to combine them. Functionally what do you do to process and combine each one? Have you done this somewhere else such as GIMP or PS.
convert \
\( 1-outerring.png -fill gray -colorize 100% \) \
\( 2-backgroundgradient.png -fill gray -colorize 100% \) \
-gravity center -composite \
\( 3-gradient.png -fill blue -colorize 100% \) \
-gravity center -composite \
\( 4-outerring.png -fill blue -colorize 100% \) \
-gravity center -composite \
\( 5-innergradient.png -fill blue -colorize 100% \) \
-gravity center -composite \
\( bikeicon.png -fill white -colorize 100% \) \
-gravity center -composite \
finalbikeicon.gif
Note since each image is exactly the same size, you can even leave off the -gravity center
Here is something close:
convert \
1-outerring.png 2-backgroundgradient.png -composite \
3-gradient.png -composite \
4-outerring.png -composite \
\( 5-innergradient.png -fill skyblue -tint 90 \) -composite \
\( bikeicon.png -channel rgb -negate +channel \) -composite \
finalbikeicon2.gif
That is why I asked for the actual processing steps you have used elsewhere to combine them. Functionally what do you do to process and combine each one? Have you done this somewhere else such as GIMP or PS.
convert \
\( 1-outerring.png -fill gray -colorize 100% \) \
\( 2-backgroundgradient.png -fill gray -colorize 100% \) \
-gravity center -composite \
\( 3-gradient.png -fill blue -colorize 100% \) \
-gravity center -composite \
\( 4-outerring.png -fill blue -colorize 100% \) \
-gravity center -composite \
\( 5-innergradient.png -fill blue -colorize 100% \) \
-gravity center -composite \
\( bikeicon.png -fill white -colorize 100% \) \
-gravity center -composite \
finalbikeicon.gif
Note since each image is exactly the same size, you can even leave off the -gravity center
Here is something close:
convert \
1-outerring.png 2-backgroundgradient.png -composite \
3-gradient.png -composite \
4-outerring.png -composite \
\( 5-innergradient.png -fill skyblue -tint 90 \) -composite \
\( bikeicon.png -channel rgb -negate +channel \) -composite \
finalbikeicon2.gif
Re: Best way to stack and color multiple images?
Thanks, this helps a lot
I haven't used any commands to change colors or stack them in the past. I currently have them all set up in Illustrator. In Illustrator I have 48x48 sized artboards, each with these images stacked on top of each other. What I do is select a gradient color with the direct select tool, select the same color from the pull down menu and then change the color there in the pallet and all of the icons are updated. I then export them as PNG or SVG (whatever is needed) with the option to "use artboards" so each icon comes out as a separate file. Then I dump them into the directory to overwrite the other files I wanted to change.
I haven't used any commands to change colors or stack them in the past. I currently have them all set up in Illustrator. In Illustrator I have 48x48 sized artboards, each with these images stacked on top of each other. What I do is select a gradient color with the direct select tool, select the same color from the pull down menu and then change the color there in the pallet and all of the icons are updated. I then export them as PNG or SVG (whatever is needed) with the option to "use artboards" so each icon comes out as a separate file. Then I dump them into the directory to overwrite the other files I wanted to change.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Best way to stack and color multiple images?
moomaster wrote:Thanks, this helps a lot
I haven't used any commands to change colors or stack them in the past. I currently have them all set up in Illustrator. In Illustrator I have 48x48 sized artboards, each with these images stacked on top of each other. What I do is select a gradient color with the direct select tool, select the same color from the pull down menu and then change the color there in the pallet and all of the icons are updated. I then export them as PNG or SVG (whatever is needed) with the option to "use artboards" so each icon comes out as a separate file. Then I dump them into the directory to overwrite the other files I wanted to change.
You can also gradient color in IM by changing
\( 5-innergradient.png -fill skyblue -tint 90 \) -composite \
to
\( 5-innergradient.png +level-colors color1,color2 \) -composite \
I had tried that, but could not find a good match to your icon by guessing at colors (for example: blue,white)
see http://www.imagemagick.org/Usage/color_mods/#tint and http://www.imagemagick.org/Usage/color_ ... vel-colors
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Best way to stack and color multiple images?
-colorize replaces (tints) all colors, including whites and blacks. It basically 'de-contrasts' all colors toward the fill color.
The use of tint to set mid-tones will work, and is probably one of the better solutions.
However be warned that the color given is not the actual final midtone color. I don't know the history behind tint, or why it works like this. Basically the percentage argument is not a 'blend percentage' but really more a 'brightness percentage'. It will for example not work at all for a 'black' fill color. (using composite overlay or hardlight works better!)
This situation could possibly be fixed for IM v7 -- IE make the percentage a blend between the parabolic tint color, and the actual image.
Also +level-colors would work too as a way of doing a full grayscale change. But you loose control of highlights! That is white in the input grayscale image is no longer white!
For techniques on this see IM examples, Color Modifications, Tinting Images
http://www.imagemagick.org/Usage/color_mods/#tinting
Now as for the composition. Rather than doing multiple compositions, a single layers "flatten" is probably the best solution. However please remember: Gravity is not available in layered images, and offsets are set using -page. As such it works best when all images are all the same size, or at least on the same sized virtual canvas, with the right offset.
Here is my scripted version...
Example usage (output to screen don't save)
then save it
Due to the nature of -tint a tint percentage option may be advisable
Alternativeally change the tint part to either a -clut or -compose overlay method (see link above)
The use of tint to set mid-tones will work, and is probably one of the better solutions.
However be warned that the color given is not the actual final midtone color. I don't know the history behind tint, or why it works like this. Basically the percentage argument is not a 'blend percentage' but really more a 'brightness percentage'. It will for example not work at all for a 'black' fill color. (using composite overlay or hardlight works better!)
This situation could possibly be fixed for IM v7 -- IE make the percentage a blend between the parabolic tint color, and the actual image.
Also +level-colors would work too as a way of doing a full grayscale change. But you loose control of highlights! That is white in the input grayscale image is no longer white!
For techniques on this see IM examples, Color Modifications, Tinting Images
http://www.imagemagick.org/Usage/color_mods/#tinting
Now as for the composition. Rather than doing multiple compositions, a single layers "flatten" is probably the best solution. However please remember: Gravity is not available in layered images, and offsets are set using -page. As such it works best when all images are all the same size, or at least on the same sized virtual canvas, with the right offset.
Here is my scripted version...
Code: Select all
#!/bin/sh
#
# create_icon [-bg color] icon_image [output_image]
#
# IM in a shell script
#
color=RoyalBlue
if [ "X$1" = "X-bg" ]; then
shift; color="$1"; shift;
fi
input_icon="$1"
output="${2:-show:}"
convert 1-outerring.png 2-backgroundgradient.png 3-gradient.png \
\( 4-outerring.png 5-innergradient.png \
-fill "$color" -tint 100% \) \
\( "$input_icon" -fill white -colorize 100% \) \
-background none -flatten \
"$output"
Code: Select all
./create_icon -bg tomato bikeicon.png
Code: Select all
./create_icon -bg tomato bikeicon.png finalbikeicon.gif
Alternativeally change the tint part to either a -clut or -compose overlay method (see link above)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/