SOLVED Only PNG images can be added by a script?
nowell last edited by gferreira
I’m working on a script that, among other things, sets the image for a glyph. Based on this thread with @cj and @frederik, I’m using the following function:
CurrentGlyph().addImage( replacementImageFilePath )
Unfortunately, I receive an error unless the image at that file path is a PNG. The error message is long, but ends with:
... AssertionError: Image does not begin with the PNG signature
I have the same image file in both JPG and PNG formats, but only the PNG will load error-free. I’m surprised to see this, because JPG and TIFF are supported for dragged-in images. Do images loaded by script need to be PNGs?
in the upcoming RF3.3!!!
nowell last edited by
Thanks, @frederik and @gferreira! After a good deal of trial and error (this is my first sizable Robofont script), I was able to get this working. Any idea when the PNG converter will move to
gferreira last edited by gferreira
here’s a script which can import images in JPEG or TIFF formats:
import os # will move to mojo.tools! from lib.tools.misc import imagePNGData imagePath = 'example.jpg' glyph = CurrentGlyph() glyph.addImage(data=imagePNGData(imagePath))
the script is using an internal function from the
libto convert the image to PNG – this is usually not advised, because the lib may change and the script will stop working. the function
imagePNGDatawill be moved to
mojo.toolsin a future release.
yes, PNG only, following the UFO spec
If you use a drag and drop of any image (png, tiff, jepg) in a glyph window it will be converted internally to a png.
If you are using a script to add an image, you have to be sure the image is png or convert it to an png!
hope this makes sense and good luck!