Compose with -channel (command line to c#)
Posted: 2019-02-05T08:38:02-07:00
Hello everyone! I'm sort of new to ImageMagick as whole and I would like to ask for your help.
I need to apply certain filters to the images (photos) as if it was in instagram or in a photoshop alike app. Filters come with different settings such as sepia, hue, gradients and compose modes. Where I get a problem is a multiply type of composition.
My filter is a half-transparent gradient such as this one (square):
Taking this example image (also square and same size):
Applying this command
will result in a half-transparent image as the alpha channel is also multiplyed throughout the image:
Of course, this is not what I am looking for so the solution is to specify the -channel parameter allowing to 'skip' the alpha
Result as expected and correct:
But the MagickImage class in .NET does not have a Composite method overload that accepts Channels enum as a parameter.
So this line
by default multiplies alpha as well resulting in the first example.
So I would really appreciate if you could help me with this one.
P. S.
Multiplying as is and then removing transparency may look like a decent workaround at first, but there is a catch.
If an original image has its own transparency (even a small part of it does) like this
Then after composition you can't tell what part was transparent in the beginning and what got its alpha by multiplying a filter.
So if removed transparency at that point it will also lose the one it was supposed to have:
I need to apply certain filters to the images (photos) as if it was in instagram or in a photoshop alike app. Filters come with different settings such as sepia, hue, gradients and compose modes. Where I get a problem is a multiply type of composition.
My filter is a half-transparent gradient such as this one (square):
Taking this example image (also square and same size):
Applying this command
Code: Select all
magick convert Image.png Overlay.png -compose Multiply -composite Result1.png
Of course, this is not what I am looking for so the solution is to specify the -channel parameter allowing to 'skip' the alpha
Code: Select all
magick convert Image.png Overlay.png -channel rgb -compose Multiply -composite Result2.png
But the MagickImage class in .NET does not have a Composite method overload that accepts Channels enum as a parameter.
So this line
Code: Select all
magickImage.Composite(overlay, CompositeOperator.Multiply);
So I would really appreciate if you could help me with this one.
P. S.
Multiplying as is and then removing transparency may look like a decent workaround at first, but there is a catch.
If an original image has its own transparency (even a small part of it does) like this
Then after composition you can't tell what part was transparent in the beginning and what got its alpha by multiplying a filter.
So if removed transparency at that point it will also lose the one it was supposed to have: