Only PNG images can be added by a script?

  • 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?

  • admin

    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!

  • admin

    hello @nowell,

    here’s a script which can import images in JPEG or TIFF formats:

    import os
    # will move to!
    from import imagePNGData
    imagePath = 'example.jpg'
    glyph = CurrentGlyph()

    the script is using an internal function from the lib to convert the image to PNG – this is usually not advised, because the lib may change and the script will stop working. the function imagePNGData will be moved to in a future release.

  • 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 Thanks!

  • admin

    in the upcoming RF3.3!!!