Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%opaque not working for WMF with text with transparent background #7295

Open
RonnyPixel opened this issue May 7, 2024 · 5 comments
Open

Comments

@RonnyPixel
Copy link

ImageMagick version

7.1.1-27 Q16-HDRI x64 0225ac4:20240121

Operating system

Windows

Operating system, version and so on

11

Description

magick identify -format "%[opaque]" .\text.wmf
True
text.zip

Steps to Reproduce

magick identify -format "%[opaque]" .\text.wmf

Images

image

@snibgo
Copy link

snibgo commented May 7, 2024

It seems the problem isn't in %[opaque], but a mis-reading of the file test.wmf. I test with the simple command:

magick test.wmf out.png

When using IM v7.1.1-28 (pre-built binary) on Windows 11, the output is 32173x13547 pixels, entirely opaque white.

When using IM v7.1.1-27 (Beta) built by me, without libwmf, the output is 912x384 pixels, entirely opaque, mostly either white or black.

When viewing text.wmf with Windows Paint, the result is similar to IM v7.1.1-27, but black characters on a transparent background.

@snibgo
Copy link

snibgo commented May 7, 2024

The size problem (32173x13547 pixels) can be fixed by supplying a sensible density, eg:

magick -density 100 text.wmf t.png

The result is grayscale, black text on a white background. This suggests that the WMF contains a problematic density.

We are getting the defaults background, which is white. We should be able to change this with -background None, eg:

magick -density 100 -background None text.wmf t.png

However, the result is entirely opaque black.

We can try a different background:

magick -verbose -background sRGB(50%,75%,95%,0.5) -density 100 text.wmf t4.png

The result is black text on an opaque blueish background. The background colour is correct, but there is no transparency. I don't know why not. Possibly a bug in IM or libwmf or something.

@RonnyPixel
Copy link
Author

RonnyPixel commented May 7, 2024 via email

@snibgo
Copy link

snibgo commented May 7, 2024

I last used WMF in the 1990s, and can't remember any details. https://en.wikipedia.org/wiki/Windows_Metafile may be useful.

We can rasterize the WMF twice, at the same density but with different backgrounds. Then (assuming no anti-alias) any pixels that are different must be background, so we can use that for opacity. Windows BAT syntax:

magick ^
  ( -density 100 -background Red text.wmf +write mpr:REDBK ) ^
  ( -density 100 -background Lime text.wmf ) ^
  -compose Difference -composite ^
  -negate ^
  mpr:REDBK ^
  +swap ^
  -alpha off -compose CopyOpacity -composite ^
  out.png

@RonnyPixel
Copy link
Author

RonnyPixel commented May 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants