pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

missing arguments in text

Open tazzz opened this issue 7 years ago • 4 comments

Using vips text render I am struggling with missing arguments accepted. Sample code

import logging
logging.basicConfig(level = logging.DEBUG)
import pyvips

image = pyvips.Image.text("Puzzling", width=100,  height= 150, dpi=300)
image.write_to_file("test.png")

results in

DEBUG:pyvips:Loaded binary module _libvips
DEBUG:pyvips:Module generated for libvips 8.4
DEBUG:pyvips:Linked to libvips 8.4
DEBUG:pyvips:Inited libvips
DEBUG:pyvips.voperation:VipsOperation.call: operation_name = text
DEBUG:pyvips.voperation:VipsOperation.call: string_options =
DEBUG:pyvips.voperation:VipsOperation.call: match_image = None
DEBUG:pyvips.vobject:VipsObject.set: name = text, value = Puzzling
DEBUG:pyvips.vobject:VipsObject.set: name = width, value = 100
DEBUG:pyvips.error:Error text does not support argument height
Traceback (most recent call last):
  File "createttftext.py", line 13, in <module>
    image = pyvips.Image.text("Puzzling", width=100,  height= 150, dpi=300)
  File "/home/funky/.local/lib/python3.6/site-packages/pyvips/vimage.py", line 128, in call_function
    return pyvips.Operation.call(name, *args, **kwargs)
  File "/home/funky/.local/lib/python3.6/site-packages/pyvips/voperation.py", line 208, in call
    '{1}'.format(operation_name, name))
pyvips.error.Error: text does not support argument height

I have the same when trying to use font and fontfile in pyvips.image.text while according to https://libvips.github.io/pyvips/vimage.html#pyvips.Image.text these arguments should work. Any idea please ?

tazzz avatar Jul 09 '19 18:07 tazzz

Hello @tazzz,

pyvips is a very "thin" wrapper: all it does is expose the features in the underlying libvips library. Support for fitting text into a box was added in 8.6 and I would guess your libvips is older than that.

With libvips 8.8 I see:

$ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.text("hello!", width=100, height=150, dpi=300)
>>> x.write_to_file("x.png")
>>> 

To make:

x

Actually, I would write:

x = pyvips.Image.text("hello!", width=100, height=150)

Now it will adjust DPI to try to fill the box. Or do:

x = pyvips.Image.text("hello!", width=100, dpi=300)

And it will render at exactly 300 DPI, wrapping the text at 100px.

jcupitt avatar Jul 10 '19 16:07 jcupitt

Oh, I just noticed, you have:

DEBUG:pyvips:Loaded binary module _libvips
DEBUG:pyvips:Module generated for libvips 8.4
DEBUG:pyvips:Linked to libvips 8.4
DEBUG:pyvips:Inited libvips

So yes, your libvips is from 2016.

jcupitt avatar Jul 10 '19 16:07 jcupitt

The docs for vips_text() explain all the options:

https://libvips.github.io/libvips/API/current/libvips-create.html#vips-text

jcupitt avatar Jul 10 '19 17:07 jcupitt

Should have thought to check the version of the packaged libvips. Ubuntu 18.04 lts ships indeed with libvips 8.4. Building from source and all good now. Thank you!

tazzz avatar Jul 11 '19 00:07 tazzz