Aug-03-2025, 12:45 AM
I am trying to convert emojis to svg images, using Python I got from github here
I adapted the Python to fit my system and paths.
When subprocess runs the command that is built:
I get a FileNotFoundError:
The file: /home/peterr/PVE/emoji2svg2png/svg/Animals & Nature - 9728 (black sun with rays).svg is created, but it is empty!
I tried some simple inkscape commands in bash, which worked ok, so I don't think inkscape is the problem:
This is the code from github, adapted a little for my setup:
Any tips please? I have never used subprocess before.
I adapted the Python to fit my system and paths.
When subprocess runs the command that is built:
Quote:/usr/bin/inkscape --export-overwrite --actions="select-by-id:text-box; object-to-path; export-id:text-box; export-id:text-box; export-do; FileClose;" /home/peterr/PVE/emoji2svg2png/svg/Animals & Nature - 9728 (black sun with rays).svg
I get a FileNotFoundError:
Quote:Traceback (most recent call last):
File "/home/peterr/PVE/emoji2svg2png/export-all-emojiV2.py", line 109, in <module>
generate_symbols()
File "/home/peterr/PVE/emoji2svg2png/export-all-emojiV2.py", line 86, in generate_symbols
write_new_letter(glyph, hex_code, decimal, name, category)
File "/home/peterr/PVE/emoji2svg2png/export-all-emojiV2.py", line 51, in write_new_letter
convert_to_path(file_name)
File "/home/peterr/PVE/emoji2svg2png/export-all-emojiV2.py", line 67, in convert_to_path
subprocess.call(command)
File "/usr/lib/python3.12/subprocess.py", line 389, in call
with Popen(*popenargs, **kwargs) as p:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.12/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/inkscape --export-overwrite --actions="select-by-id:text-box; object-to-path; export-id:text-box; export-id:text-box; export-do; FileClose;" /home/peterr/PVE/emoji2svg2png/svg/Animals & Nature - 9728 (black sun with rays).svg'
The file: /home/peterr/PVE/emoji2svg2png/svg/Animals & Nature - 9728 (black sun with rays).svg is created, but it is empty!
I tried some simple inkscape commands in bash, which worked ok, so I don't think inkscape is the problem:
Quote:# works
/usr/bin/inkscape --export-type="png" greenArrow1.svg
# worked but empty file
inkscape --export-type="png" symbol-template.svg
# works
inkscape --export-type="png" greenArrow1.svg
# read svg export as pdf
cat greenArrow1.svg | inkscape --pipe --export-filename=greenArrow1.pdf
This is the code from github, adapted a little for my setup:
#! /usr/bin/python3
import os
import subprocess
from typing import List, TextIO
# Reads a font and generates an SVG file for every emoji
savepath = "/home/peterr/PVE/emoji2svg2png/svg/"
# UTF8 encoded table which all Unicode symbols
# Header: Symbol;Hex-Code;Name;Is-Emoji (0 | 1);Group
# Example: ๐;1F44D;THUMBS UP SIGN;1;Body;
# Only symbols which are marked with Is-Emoji (1) are processed.
symbol_table = "/home/peterr/PVE/emoji2svg2png/symbol-table.csv"
# Simple SVG-Template with one centered symbol.
symbol_template = "/home/peterr/PVE/emoji2svg2png/symbol-template.svg"
# font name to replace Arial with.
font = "NotoColorEmoji"
# try with either path, still get FileNotFoundError
#inkscape_path = 'inkscape '
inkscape_path = '/usr/bin/inkscape'
action_object_to_path = ' --export-overwrite --actions="select-by-id:text-box; object-to-path; export-id:text-box; '
# export-id:text-box; is here a second time
action_export = 'export-id:text-box; export-do; FileClose;" '
# Set True to print all executed commands
#debug = False
debug = True
# Writes a unicode emoji as svg into the savepath
def write_new_letter(glyph, hex_code, decimal, name, category):
# the actual text file name
letter_template: TextIO = open(symbol_template, "r")
template_letter = "A"
file_name = savepath + category + " - " + str(decimal) + " (" + name.lower() + ").svg"
#new_letter = open(file_name, "x", encoding='utf-8') # think "x" means exclusive, fails if exists
new_letter = open(file_name, "w", encoding='utf-8')
lines: list[str] = letter_template.readlines()
export_data = []
for line in lines:
export_data += line \
.replace(">" + template_letter + "<", ">" + glyph + "<") \
.replace("Arial", font)
new_letter.writelines(export_data)
new_letter.close()
convert_to_path(file_name)
##def convert_to_path(file_name):
## input_file = '"' + file_name + '"'
## command = inkscape_path + action_object_to_path + action_export + input_file
## if debug:
## print(command)
## subprocess.call(command)
## print("New symbol: " + input_file)
def convert_to_path(file_name):
command = inkscape_path + action_object_to_path + action_export + file_name
if debug:
print(command)
subprocess.call(command)
print("New symbol: " + file_name)
# Reads all Unicode-Emoji which are listed in the $symbol_table.
# Only symbols which are marked with Is-Emoji (1) are processed.
def generate_symbols():
emoji_list = open(symbol_table, "r", encoding='utf-8')
i = 0
for line in emoji_list:
i = i + 1
values = line.split(",")
glyph = values[0]
hex_code = values[1]
decimal = int(hex_code, 16)
name = values[2]
is_emoji = values[3] == "1"
category = values[4].strip()
if is_emoji:
write_new_letter(glyph, hex_code, decimal, name, category)
##def generate_symbols():
## with open(symbol_table) as infile:
## emoji_list = infile.readlines()
## i = 0
## for line in emoji_list:
## # there is a \n from the csv at the end of each line
## line = line.strip()
## i = i + 1
## values = line.split(",")
## glyph = values[0]
## hex_code = values[1]
## decimal = int(hex_code, 16)
## name = values[2]
## is_emoji = values[3] == "1" # True if values[3] == 1
## category = values[4]
## if is_emoji:
## write_new_letter(glyph, hex_code, decimal, name, category)
if __name__ == '__main__':
print("Exporting all emoji...")
generate_symbols()
print("Finished export")subprocess doesn't process the command properly. It seems to think the whole command is a file name.Any tips please? I have never used subprocess before.
