-
-
Save bendmorris/7170209 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# To use, move the potrace binary to potrace-bin, then place this script | |
# somewhere on the path so that it'll be found by fontforge. | |
# After autotracing, you'll need to apply the following transformation: | |
# scale uniform 10%, using glyph origin as the origin | |
# get the last parameter passed by fontforge - the name of the temp img file | |
for last; do true; done | |
# get all of the other parameters | |
length=$(($#-1)) | |
array=${@:1:$length} | |
# get the size of the passed image | |
size=$(identify $last | grep -Po "[0-9]+x[0-9]+" | head -1) | |
# multiply that size by 10 | |
newsize=$(python -c "x = '$size'; print('x'.join([str(int(i)*10) for i in x.split('x')]))") | |
# scale up 10x and then use potrace to trace the pixelated outline | |
cat $last | mkbitmap -s 1 | convert -scale $newsize - - | potrace-bin -a 0 $array |
Ohhh I figured out how to run it --I didn't realize potrace
is an actual library/tool that I can get from:
sudo apt install potrace
,
and as stated above, that installs mkbitmap
with it (for me, these 2 binaries were installed to /usr/bin/potrace
and /usr/bin/mkbitmap
)
Fixes I figured out:
-
This script is called
potrace
because it's supposed to replace thepotrace
that you have installed.
Instead of confusingly renaming it topotrace-bin
, I called itpotrace-original
.
Then, this script should get saved to/usr/bin/potrace
, and calls the/usr/bin/potrace-original
binary to do the rest. -
I also moved the
magick
file to/usr/bin/magick
, and modified the script above to say magick convert instead of just convert on Line 17. It didn't know where the "convert" command was coming from.
Now that that's all sorted out, I called Element > Autotrace
in FontForge and am getting a Python error I believe:
ValueError: invalid literal for int() with base 10: ''
Then another error when calling magick convert
-- it says:
convert: no images defined `-' @ error/convert.c/ConvertImageCommand/3285.
And finally a 3rd error:
potrace: stdin: empty file
Time to figure this out..
I've only spent a week or so in Python.. I wonder why it's saying the i
being passed into int(i)
is empty?
for whom it may concern...
newsize=$(python -c "x = '$size'; print('x'.join([str(int(i)*10) for i in x.split('x')]))")
use python3 instead of python up there
I also tried to make this work on Ubuntu 20.04 but without success so far. On my 18.04 Ubuntu with FontForge from 2017 it works without any problems. Btw using python3 instead did not have any effect for me.
I tried to use an older potrace version --> no difference
Currently Im trying to compile the fontforge version from 2017 since I cant find a release from that time
If anyone finds a solution please post it here, thx!
I might have a lead on whats happening here. if it doesn't work even if you switched to python3, the whole sequence probably didn't happen at all, because if you have been using python 2, the program would fail on the print() statement since it's illegal syntax
did you see any outputs on the console?
I might have a lead on whats happening here. if it doesn't work even if you switched to python3, the whole sequence probably didn't happen at all, because if you have been using python 2, the program would fail on the print() statement since it's illegal syntax
did you see any outputs on the console?
I just tried it again with a fresh installation and now it just works.. my god that have been 4 hours now...Thanks a lot for your reply :)
For anyone who is (after all this time) still interested in getting this to work, just follow these simple steps for a fresh installed Ubuntu 20.04:
sudo apt-get update
sudo apt-get install potrace imagemagick fontforge
Python 3 is already preinstalled, so nothing to be done there.
Then, create a file called potrace
in your /usr/local/bin (leave the original potrace binary as it is)
sudo nano /usr/local/bin/potrace
(or any other editor of your choice)
paste the following shell script there (its the same as above just with python3 and with an explicite call of the potrace binary in the /usr/bin folder) and save it
#!/bin/bash
# To use, move the potrace binary to potrace-bin, then place this script
# somewhere on the path so that it'll be found by fontforge.
# After autotracing, you'll need to apply the following transformation:
# scale uniform 10%, using glyph origin as the origin
# get the last parameter passed by fontforge - the name of the temp img file
for last; do true; done
# get all of the other parameters
length=$(($#-1))
array=${@:1:$length}
# get the size of the passed image
size=$(identify $last | grep -Po "[0-9]+x[0-9]+" | head -1)
# multiply that size by 10
newsize=$(python3 -c "x = '$size'; print('x'.join([str(int(i)*10) for i in x.split('x')]))")
# scale up 10x and then use potrace to trace the pixelated outline
cat $last | mkbitmap -s 1 | convert -scale $newsize - - | /usr/bin/potrace -a 0 $array
make the file executable
sudo chmod 0755 /usr/local/bin/potrace
Then start FontForge, import your bdf as background and use the autotrace on the elements you like :)
This is 7 years old, I can't guarantee it still works and I'm not in a position to update it.