opacity + rotation control for specific layers

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
zsero
Posts: 9
Joined: 2011-07-13T13:55:51-07:00
Authentication code: 8675308

opacity + rotation control for specific layers

Post by zsero »

I would like to -flatten multiple animations into a single animation, using image sequences. I've written a code which does the merging, however at the moment it is only doing basic operations. At the moment this is all the code (of course with the specific image names from the sequence):

Code: Select all

convert a.png b.png c.png d.png -background transparent -flatten out.png
What i would like to ask, is that how would it be possible to:

1. flip vertically / flip horizontally / rotate by 180 degrees specific "layers". For example what would be the code if I would like to have b.png rotated by 180 degrees, while keeping a.png and c.png in place.

2. Fade in and out specific layers in an animation. In practise, I think it means providing an opacity value for a given layer for a given frame. So, I think this question is basically: how to adjust opacity (0-100%) for a specific layer while keeping the others intact.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: opacity + rotation control for specific layers

Post by fmw42 »

For 1. and 2., use parenthesis processing around each animation to restrict the processing to those images. see http://www.imagemagick.org/Usage/basics/#parenthesis

example assuming your command works as is:

convert a.png \( b.png -rotate 90 \) c.png d.png -background transparent -flatten out.png


To change a layer's opacity

convert a.png[3] -channel a -evaluate set 50% +channel result_layer3.png

that will make the 4th layer of a.png 50% transparent. (Layers in IM start with 0, nominally)

see
http://www.imagemagick.org/Usage/basics/#sequence
http://www.imagemagick.org/script/comma ... isfira77m5
zsero
Posts: 9
Joined: 2011-07-13T13:55:51-07:00
Authentication code: 8675308

Re: opacity + rotation control for specific layers

Post by zsero »

fmw42 wrote:To change a layer's opacity
convert a.png[3] -channel a -evaluate set 50% +channel result_layer3.png
that will make the 4th layer of a.png 50% transparent. (Layers in IM start with 0, nominally)
Thanks, the first example is clear, but this one confuses me.

1. What is a.png[3]? Is it an image sequence operator? I am processing image sequences, but I will process them line by line, not using [n] brackets, just convert.exe a0123.png b1234.png etc. Do I need a[3]?

2. What is +channel result_layer3.png? I would prefer to do everything like:

Code: Select all

convert a.png \( b.png -rotate 90 \) c.png d.png -background transparent -flatten out.png
Is it possible to do so with this transparency command? For me it seems that it is saving a temporary file "result_layer3.png". What I am looking for is a command like this:

Code: Select all

convert a.png \( b.png -opacity 50 \) c.png d.png -background transparent -flatten out.png
is there such a command?

3. Are you sure that "set" operation is presaving the alpha information? For me it seems from the documentation that it sets a solid color (or grey value) for all the layer, discarding the information presented in the layer. What I would like is that when it is at 0 (or 100, all programs call it different), then the result is the original image file. If it is at 100 then the result is a totally transparent image. And when it is between 1 and 99 then the result is the original image's alpha channel, multiplied by a value between 0 and 1. Should I use "-evaluate multiply 0.5"?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: opacity + rotation control for specific layers

Post by fmw42 »

convert a.png \( b.png -opacity 50 \) c.png d.png -background transparent -flatten out.png

is there such a command?

3. Are you sure that "set" operation is presaving the alpha information? For me it seems from the documentation that it sets a solid color (or grey value) for all the layer, discarding the information presented in the layer. What I would like is that when it is at 0 (or 100, all programs call it different), then the result is the original image file. If it is at 100 then the result is a totally transparent image. And when it is between 1 and 99 then the result is the original image's alpha channel, multiplied by a value between 0 and 1. Should I use "-evaluate multiply 0.5"?
Then define what you mean by change the opacity to half. If you want to preserve the current alpha channel but make it half the alpha value, then your result is correct.

convert a.png \( b.png -channel a -evaluate multiply 0.5 +channel \) c.png d.png -background transparent -flatten out.png

The -channel a, selects the alpha channel only so that the -evaluate only applies to it. The +channel turns back on all channels with the modified alpha channel.

b.png[4] means the 5th frame/layer of the animation
zsero
Posts: 9
Joined: 2011-07-13T13:55:51-07:00
Authentication code: 8675308

Re: opacity + rotation control for specific layers

Post by zsero »

fmw42 wrote:
convert a.png \( b.png -opacity 50 \) c.png d.png -background transparent -flatten out.png

is there such a command?

3. Are you sure that "set" operation is presaving the alpha information? For me it seems from the documentation that it sets a solid color (or grey value) for all the layer, discarding the information presented in the layer. What I would like is that when it is at 0 (or 100, all programs call it different), then the result is the original image file. If it is at 100 then the result is a totally transparent image. And when it is between 1 and 99 then the result is the original image's alpha channel, multiplied by a value between 0 and 1. Should I use "-evaluate multiply 0.5"?
Then define what you mean by change the opacity to half. If you want to preserve the current alpha channel but make it half the alpha value, then your result is correct.

convert a.png \( b.png -channel a -evaluate multiply 0.5 +channel \) c.png d.png -background transparent -flatten out.png

The -channel a, selects the alpha channel only so that the -evaluate only applies to it. The +channel turns back on all channels with the modified alpha channel.

b.png[4] means the 5th frame/layer of the animation
Thanks, its clear now!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: opacity + rotation control for specific layers

Post by anthony »

Going back to the original problem...

You mentioned animations but your example uses PNG images whcih are by defintion single images, not animations.
Are these images ment to be individual frames?

If you animations are small enough to be handled completely in memory you can flatten the multiple animations together as a whole. The -flatten operator is basically just simplier image composition, and IM can compose two separate sequences (animations) together (of equal number of frames).

See Layers Composition...
http://www.imagemagick.org/Usage/anim_mods/#composite

If your animations do not have the same timing, or number of frames, then a extra step is needed first.
See Merging Time Disjoint Animations
http://www.imagemagick.org/Usage/anim_mods/#merge


As for modifing one frame in a particular way you can 'pull out' that frame into a parenthesis, modify it, and 'put it back'.
This is a very common thing to do...
Frame by frame modification...
http://www.imagemagick.org/Usage/anim_mods/#frame_mod
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
zsero
Posts: 9
Joined: 2011-07-13T13:55:51-07:00
Authentication code: 8675308

Re: opacity + rotation control for specific layers

Post by zsero »

anthony wrote:Going back to the original problem...

You mentioned animations but your example uses PNG images whcih are by defintion single images, not animations.
Are these images ment to be individual frames?

If you animations are small enough to be handled completely in memory you can flatten the multiple animations together as a whole. The -flatten operator is basically just simplier image composition, and IM can compose two separate sequences (animations) together (of equal number of frames).

See Layers Composition...
http://www.imagemagick.org/Usage/anim_mods/#composite

If your animations do not have the same timing, or number of frames, then a extra step is needed first.
See Merging Time Disjoint Animations
http://www.imagemagick.org/Usage/anim_mods/#merge


As for modifing one frame in a particular way you can 'pull out' that frame into a parenthesis, modify it, and 'put it back'.
This is a very common thing to do...
Frame by frame modification...
http://www.imagemagick.org/Usage/anim_mods/#frame_mod
I am doing animations, but I am processing images one by one. I wrote a C++ application, which calls system( "convert.exe ... " ), because this way I have better control and more experience with what I want to achieve. Maybe it could be a little bit faster in pure IM, but this way I can control everything frame by frame. For example I can do: a.png b.png (with opacity 99%) c.png ... a.png b.png (with opacity 98%) c.png, etc. Also, I am trying to process 300 images for every single frame, so that's a no go for memory processing image sequences... I even had to come up with an idea for the command line limit. Now I process the 300 images in 5 sub-commands into 5 sub-images and merge them only at the end in a final convert command.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: opacity + rotation control for specific layers

Post by anthony »

zsero wrote:I am doing animations, but I am processing images one by one. I wrote a C++ application, which calls system( "convert.exe ... " ), because this way I have better control and more experience with what I want to achieve. Maybe it could be a little bit faster in pure IM, but this way I can control everything frame by frame. For example I can do: a.png b.png (with opacity 99%) c.png ... a.png b.png (with opacity 98%) c.png, etc. Also, I am trying to process 300 images for every single frame, so that's a no go for memory processing image sequences... I even had to come up with an idea for the command line limit. Now I process the 300 images in 5 sub-commands into 5 sub-images and merge them only at the end in a final convert command.
Understood.

IMv7 should make this a lot easier with the planned co-processing technqiue. That way you only need one IM running in background, and you can have it load, process and save images as needed under program control. at least that is the plan, though it may be some time before it become available for general use.
http://www.imagemagick.org/Usage/bugs/I ... ipting.txt
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply