Page 1 of 1

transparency changes in IM 7

Posted: 2019-09-16T05:28:27-07:00
by dognose
I'm trying to update a number of scripts to IM 7. Many involve transparency or overlays that seem to be messing up.
I still don't quite understand the changes from transparency to alpha

Does anyone have a simple this => that for conversion list of 6 to 7 ?

Here is an example :
convert black.png -fill red -opaque white -transparent black red.png

Image

in IM 6: desired result

Image

in im 7, it's completely blank

Re: transparency changes in IM 7

Posted: 2019-09-16T05:53:46-07:00
by snibgo
See the v7 porting guide: http://www.imagemagick.org/script/porting.php
Reading gray-scale images generate an image with only one channel. If that image is to then accept color the -colorspace setting needs to be applied to expand the one channel into separate RGB (or other) channels.
So, insert "-colorspace sRGB" after the input filename.

Re: transparency changes in IM 7

Posted: 2019-09-16T06:29:17-07:00
by dognose
That works great, thanks!

Re: transparency changes in IM 7

Posted: 2019-09-16T06:42:14-07:00
by dognose
Ok, how about this one:

composite input.gif -compose src-over blend.gif mask.gif output.gif

The mask being a black and white shape.

I'm guessing I have to convert the black and white to alpha channel?

Re: transparency changes in IM 7

Posted: 2019-09-16T07:51:49-07:00
by dognose
Or, this one, I'm trying to cutout a shape from the image

composite input.jpg -gravity center -compose CopyOpacity shamrock.gif -resize 400x300 out.gif

input.jpg
Image
shamrock.gif
Image
With im 6 I get:
Image

with im 7 I get:
Image

Any ideas how to adjust that?

Re: transparency changes in IM 7

Posted: 2019-09-16T08:12:38-07:00
by snibgo
Please show your inputs, not just the outputs.

I never use "composite" for anything. I use "convert" for v6 or "magick" for v7, with the "-composite" operation. This needs the two inputs in the opposite order.

Re: transparency changes in IM 7

Posted: 2019-09-16T08:45:16-07:00
by dognose
added the inputs above. ... with your changes still see the same problem. reversing order doesn't work though.
magick -gravity center -compose CopyOpacity input.jpg shamrock.gif -resize 400x300 -composite out.gif

Re: transparency changes in IM 7

Posted: 2019-09-16T09:22:00-07:00
by fmw42
IM 7 is more sensitive the syntax order. Your syntax is wrong. Read the input before any processing

This works for me.

magick input.jpg \( shamrock.gif -resize 400x300 \) -gravity center -compose CopyOpacity -composite out.gif

See
https://imagemagick.org/Usage/basics/#cmdline
https://imagemagick.org/Usage/compose/#compose
https://imagemagick.org/Usage/basics/#parenthesis

Re: transparency changes in IM 7

Posted: 2019-09-17T09:33:19-07:00
by dognose
That doesn't work, I still get the same thing.

Re: transparency changes in IM 7

Posted: 2019-09-17T09:48:00-07:00
by fmw42
The issue is that the aspect of the two images are not the same. So the shamrock when resized is not the same size as the input and would need the black area extended to the same size as the input. So for IM 7 on unix, try the following which works for me.

Code: Select all

magick input.jpg -set option:dims "%wx%h" \
\( shamrock.gif -resize 400x300 -background black -gravity center -extent "%[dims]" \) \
-gravity center -compose CopyOpacity -composite out.gif

Re: transparency changes in IM 7

Posted: 2019-09-18T10:23:03-07:00
by dognose
Ok, thanks. I wouldn't have though that!

Re: transparency changes in IM 7

Posted: 2019-09-18T15:50:16-07:00
by GeeMack
dognose wrote:
2019-09-16T07:51:49-07:00
Any ideas how to adjust that?
Another method for achieving this result would be to create a transparent canvas first, then read in the main input image, then the shamrock mask. imageMagick's default behavior when doing a "-composite" operation with three inputs is to use the third image as a mask, so a command like this...

Code: Select all

magick xc:none input.jpg shamrock.gif -resize 400x300 -gravity center -composite out.gif
... should output the orange flower image in the shape of the shamrock mask on a transparent background.

That transparent layer "xc:none" starts as a 1x1 canvas, so the "-resize" makes it 300x300. Since it's the first layer, the rest of the composite follows its dimensions, etc.

This command should work exactly the same way with IM v6 by using "convert" instead of "magick".