I've installed font-forge for windows 10. I am currently using python 3.7 and I want to convert image to font. So what I am trying to do is to convert image to .svg using Potrace then converting .svg to font by font-forge. (Better suggestions to convert image to font are also welcomed.)
I know that I can open fontforge-console.bat file and write ffpython <filename.py> to do this.
But I want to make font forge a pyhton extension so that I can just do it by importing it like "import fontforge" in the python file.
How to do this?
There is a python library for python2:
import fontforge # only works with python2
I have recently developed a script for batch processing svg files to TrueType fonts using FontForge. I have tested it only on linux, but you can try it on Windows. fontforge executable must be in PATH and it requires Pythos 3.6+
https://github.com/mnesarco/ff-batch
Related
I want to have python save an image file of the whole screen as a variable with ctypes so that I could access the screen in a program and do something with it (like put it on a pygame window). I can't use any other libraries unless they are included with python (no installing or pip). Does anyone know how to do this?
Edit: I'm using windows 10.
PIL.ImageGrab is from PILLOW (a python image library fork which you can install with pip). You can give a bounding box or capture the entire screen.
Update: OP now mentions he can't use external libraries.
Then you could virtually hit printscreen and read the clipboard. The code of PILLOW is open-source feel free to use it.
Remember that you can always call a command from within python:
>>> import os
>>> os.system("pip install pillow")
Or download the zip of the library and import it in your code.
in windows explorer, you can choose to show the dimensions of files (images), is there a way to get that metadata with python without PIL, maybe os
You should see this Python Module:
https://pypi.org/project/ExifRead/
My goal is to generate (in Python under Windows) a bitmap image rendering any unicode character, including in particular emojis. I have installed several emoji-friendly fonts (including Symbola) for testing purpose.
So far I've tried PIL, matplotlib and pygame, but none of these are able to do it under Windows (the first two apparently can do it on some versions of Linux / MacOS, while pygame is explicitly limited to characters up to 0xffff, which rules out emojis).
I found that reportlab is able to generate a PDF with emojis (while its bitmap renderer fails to properly render them), but I still need to find a way to extract the emoji character from the PDF and convert it to bitmap. I feel like there has to be a simpler way...
NB: this question is related to Rendering Emoji with PIL but I do not necessarily want to use PIL if another library can do the job
I eventually found a solution in Is there any good python library for generating and rendering text in image format?. Although it is based on a third-party executable, as mentioned it is easy to wrap in Python.
Exact steps were as follows:
Install ImageMagick from https://www.imagemagick.org/script/download.php#windows
Set environment variable MAGICK_HOME to installation folder
Install Pillow to be able to manipulate easily the resulting image in Python (conda install pillow)
Download and install the Symbola font from https://fontlibrary.org/en/font/symbola
And my test script:
import os
import subprocess
import PIL.Image
to_render = '🤓'
output_file = 'rendered_emoji.bmp'
subprocess.run([
os.path.join(os.environ['MAGICK_HOME'], 'magick.exe'),
'convert', '-font', 'Symbola', '-size', '50x50',
'-gravity', 'center', f'label:{to_render}', output_file])
image = PIL.Image.open(output_file)
image.show()
I'm trying to use this blog post to convert one pdf to a jpg, however everytime I try to run this simple script I get this exception wand.exceptions.WandError: wand contains no images MagickWand-56' # error/magick-image.c/MagickWriteImage/13001
from wand.image import Image
with Image(filename="myFile.pdf") as img:
img.save(filename="myFile.png")
I'm using the latest version of Wand and Python 3.4.2. The only thing I can think of is possibly a version compatibility issue.
So just to close the question, the problem is missing ghostscript library on mac, as indicated in my comment above:
"maybe then some libraries missing. do you use linux/windows/mac?
check what is required there for pdfs? ghostscript maybe? "
I'm running Python 3.1 on Windows and I'm trying to distribute my Pygame script as an executable via cx_Freeze. Right now it seems to be working except that the exe build can't load any of my images:
Cannot load image: C:\path\to\build\exe.win32-3.1\resources\image.png
File is not a Windows BMP file
Googling has revealed that this happens when the SDL imaging library doesn't get included correctly. However, SDL_image.dll and libpng12-0.dll are both put by cx_Freeze into my build directory, so it seems to me like everything should be fine. Why wouldn't it be able to load PNG images?
EDIT: I "solved" this problem by porting my script to Python 2.6 and using py2exe instead since it had some functionality anyway that I needed.
I encountered the same issue many times, but I found out how to deal with it.
The problem
It seems that there is a conflict between two possible dependencies. The file jpeg.dll is included from the JRE (on Windows, something like C:\Program Files\Java\jre6\bin\), but it is the wrong one. It should be included from the Pygame directory, located within your Python installation, at C:\Python31\lib\site-packages\pygame\. Don't know why cx_Freeze prefers the one from the JRE, though…
How to fix it?
It is quite easy. Just copy the correct file (the one from Pygame) to the directory in which you execute the cx_Freeze script. When you will start it, the script will look in the current directory first, and will find the correct jpeg.dll. Your executable should be able to import PNG images now.
Test by inserting some python code to display one message indicating that the libraries have loaded and another message to indicate that their loading resulted in an error.
try:
import SDL_image
print "Loaded SDL_image"
except:
print "Failed to import SDL_image"
try:
import libpng
print "Loaded libpng"
except:
print "Failed to import libpng"