0

I'm trying to write a file with a Unicode file name, *️⃣.png, inside a folder with other image files.

In UTF-8, this gets encoded to *\xef\xb8\x8f\xe2\x83\xa3.png. The asterisk is causing some issues with subprocess. It appears to be acting as a wildcard in a glob.

The following code reproduces the issue:

import subprocess
from pathlib import Path

ICON_CACHE_PATH = Path('/tmp')

icon_path_9 = Path(ICON_CACHE_PATH / '9️⃣.png')
icon_path_star = Path(ICON_CACHE_PATH / '*️⃣.png')
subprocess.call([
    'convert', '-pointsize', '64', '-background', 'transparent',
    f'pango:{icon_path_9.stem}', icon_path_9
])
subprocess.call([
    'convert', '-pointsize', '64', '-background', 'transparent',
    f'pango:{icon_path_star.stem}', icon_path_star
])
print(icon_path_star.exists())

Instead of creating both *️⃣.png and 9️⃣.png, with the images of the Unicode characters, I end up with a single file 9️⃣.png, with an asterisk in it.

The above code prints False.

How can I create both files, with the correct images?

[Edit] This is probably just a ImageMagick issue. Running other binaries, such as stat, on this file works fine. I just used a temporary file name for ImageMagick, and used Python to rename it again. Although any suggestions for how to escape it in ImageMagick is welcome.

simonzack
  • 19,729
  • 13
  • 73
  • 118
  • 1
    `\xef\xb8\x8f` is actually the Unicode "variation" character `+UFE0F`. See [this](https://stackoverflow.com/questions/38100329/what-does-u-ufe0f-in-an-emoji-mean-is-it-the-same-if-i-delete-it#38100927). – xenoid Jun 19 '22 at 07:32
  • Can you run `convert` command directly in a bash shell, to see if `*️⃣.png` gets generated ? – Philippe Jun 19 '22 at 11:38
  • @Philippe I tried it in *Zsh*. `*️⃣.png` doesn't get generated. The same problem occurs. Adding quotes doesn't help. – simonzack Jun 19 '22 at 14:24
  • Is `convert` a binary program or a script ? – Philippe Jun 19 '22 at 15:47

0 Answers0