libvips / lua-vips

Lua binding for the libvips image processing library
MIT License
125 stars 10 forks source link

Text only renders with font file that was loaded first #58

Closed piface314 closed 7 months ago

piface314 commented 7 months ago

I have multiple .ttf fonts in different file paths, and in my application, if I try to create two text images with different font files, only the first one is properly rendered with the font.

For instance, running the code:

vips.Image.text("TEST1", {font = "Stone Serif 10", fontfile = "stone-serif.ttf", dpi = 300}):write_to_file("test1.png")
vips.Image.text("TEST2", {font = "MatrixBoldSmallCaps 10", fontfile = "matrix.ttf", dpi = 300}):write_to_file("test2.png")

produces:

test1 test2

If I swap the lines, I get a different result:

test1 test2

What could be the reason behind this?

vips version: 8.12.1

jcupitt commented 7 months ago

Hi @piface314,

There have been a few fixes to font handling since 8.12 (three years ago). I would update your libvips.

I tried with current stable:

#!/usr/bin/luajit

vips = require "vips"

local image = vips.Image.text("TEST1", {
    font = "MissFajardose 10", 
    fontfile = "/home/john/pics/MissFajardose-Regular.ttf",
    dpi = 600
})
image:write_to_file("test1.png")

image = vips.Image.text("TEST2", {
    font = "PT Serif, Bold 10",
    fontfile = "/home/john/pics/PT_Serif-Web-Bold.ttf",            
    dpi = 600
})
image:write_to_file("test2.png")

To make:

test1 test2

I get the same result if I swap the two text render operations.

piface314 commented 7 months ago

Oh, I see. I was using this version because it seems to be the newest version available on apt. In this case, should I build from source?

jcupitt commented 7 months ago

Yes, or update your OS, of course. There are various libvips PPAs as well.

piface314 commented 7 months ago

Thanks! I found a PPA with a more recent version and it solved the problem.