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

  • If you need to work with JPG images, you could consider converting them to PNG format before adding them through the script.

    And hey, if you ever need to optimize those JPG files for better performance or smaller sizes, check out jpg compress tools. They can help maintain image quality while reducing file sizes effectively.

  • BTW, it seems like you're encountering an issue with your script. While PNG files work smoothly with the addImage() function, other formats like JPG might trigger errors due to format compatibility. Although JPG and TIFF are supported for manual dragging, scripts might have specific requirements.

  • Exploring any script-specific documentation or reaching out to the script's developers might shed more light on this matter.

  • admin

    in the upcoming RF3.3!!!

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

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

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