transparency changes in IM 7

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
dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

transparency changes in IM 7

Post by dognose » 2019-09-16T05:28:27-07:00

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

snibgo
Posts: 12436
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: transparency changes in IM 7

Post by snibgo » 2019-09-16T05:53:46-07:00

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.
snibgo's IM pages: im.snibgo.com

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: transparency changes in IM 7

Post by dognose » 2019-09-16T06:29:17-07:00

That works great, thanks!

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: transparency changes in IM 7

Post by dognose » 2019-09-16T06:42:14-07:00

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?

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: transparency changes in IM 7

Post by dognose » 2019-09-16T07:51:49-07:00

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?
Last edited by dognose on 2019-09-16T08:40:16-07:00, edited 2 times in total.

snibgo
Posts: 12436
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: transparency changes in IM 7

Post by snibgo » 2019-09-16T08:12:38-07:00

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.
snibgo's IM pages: im.snibgo.com

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: transparency changes in IM 7

Post by dognose » 2019-09-16T08:45:16-07:00

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

User avatar
fmw42
Posts: 25764
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: transparency changes in IM 7

Post by fmw42 » 2019-09-16T09:22:00-07:00

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

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: transparency changes in IM 7

Post by dognose » 2019-09-17T09:33:19-07:00

That doesn't work, I still get the same thing.

User avatar
fmw42
Posts: 25764
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: transparency changes in IM 7

Post by fmw42 » 2019-09-17T09:48:00-07:00

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

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: transparency changes in IM 7

Post by dognose » 2019-09-18T10:23:03-07:00

Ok, thanks. I wouldn't have though that!

User avatar
GeeMack
Posts: 729
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: transparency changes in IM 7

Post by GeeMack » 2019-09-18T15:50:16-07:00

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".

Post Reply