Can font be read in png or jpg format in glyphs through Python scripts

Hello, I would like to inquire. Currently, the fonts in glyphs are all vector, but I want to read the font in the form of pixel png or jpg to read the entire image. Is there a way to convert it

Do you like to use the bitmaps in your font? Then please have a look at the color font tutorials.

Or, do you like to automatically convert the shapes in those images to vectors? There is a tracing plugin ninths plugin manager. You should be able to run that from a script. But the outline quality might not be good enough. I’m working on a improved version of that plugin. It would be very helpful if you could send me one of your images to test the new algorithm.

You can place images in glyphs, just drag them into the glyph. Or assign them, if they have file names that are the same as the glyph names.

Yes, I am writing a plugin to obtain the visual center of a font, which needs to be based on bitmaps for judgment. Therefore, I want to obtain the pixel values of my font from the pixels inside the path, that is, the entire layer. Therefore, it is necessary to perform read conversion.

You have to explain more what you are trying to do. What your starting point is, what you like to do and what should be there are the end. Send a private massage if you don’t like to explain this in public.

I want to obtain the visual area of a character, which is the main part of the font, as shown in the rectangular box in the figure. This needs to be judged by the difference in pixel values between the font and background, so the key step is to convert the vector image created in glyphs into a bitmap for judgment.

I have already implemented this function on a bitmap, based on opencv. The key step is to obtain the pixels of the vector image font

I don’t understand what you mean, but I hope to use a Python script to read the pixel values of the entire layer using the vector font created by glyphs.

It would be much easier to read the pixels directly instead of converting them to path. There are may python modules to do that.

Do you mean that Python will directly read the pixels of vector maps created by glyphs

But when a font is created using glyphs, it is first a vector graph composed of paths. I did not convert to path

I want to operate all of this in glyphs, so I don’t want to manually convert vector images into bitmaps and save them, and then use libraries such as OpenCV to read pixels.

I just know that the filter ‘glyph to Image’ can save font as png. So since it can be saved, it can be converted itself. Is there a function that can be called? I just need to convert, not save.

Can you explain what data you like to compute. Not how you think you need to implement it.

I want to calculate the pixel value of the entire image

What does that mean? Do you need the ratio of black and white pixels, or the visual center …?

the visual center

It’s the visual center, not the center of the object’s boundary

I need black and white pixels in order to obtain the visual center

You can do it in two ways:

  1. get the bezierpath of the layer, then iterate all coordinates you are interested in and check bezierpath.containsPoint_(point). It will return True for black and False for white.
  2. make a new NSImage, draw the bezierpath into it (use the right image size and shift the paths to get the right portion of the path). Then get to the bitmapRepresentation of that image and look over the pixels.

Both will give you the same result. Not sure what is faster.