-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose vips_text to create an image containing rendered text #512 #3252
Conversation
Hi again @lovell, I installed a fresh ubuntu image via docker with libvips dependencies, node 16.15, valgrind ... and now have only one error remaining on the existing tests (even on main branch). The error occurs in test/util.js (Vendor -> Contains expected attributes) :
The sharp.vendor.installed variable in my case contains this (the installed array is empty) : Any clue about that ? Also i have some of my own tests failing right now ... i'm having a look. Thanks for your help |
Hello @lovell, This is me again. I now understand why i have failures on my own (new) tests. Generated image based on text can be quite different depending on the OS and font combination. That's why i introduced a specific font file for the tests ... but that's not that easy :-) I did some tests using different vips command to see the difference between MacOs / Linux (Windows is not even in the equation). Here's only two of them :
Identifying a font that can give the « same » results across the different Oses and keeping the fixtures.assertSimilar() in the unit tests may not be a viable option. Maybe @jcupitt can give some insights about this ? Thanks in advance for your help regarding this issue. PS : I still have the vendor unit test failing locally Best regards, |
Hi @brahima Text rendering is really complex, and tiny changes to your system can completely alter the bitmap you get. You can't expect to get the same result from ubuntu 21.04 and 21.10, for example, never mind between macos and linux. You can't even expect two users both on ubuntu 22.04 to get the same result. I would just check that the generated text image has a not-crazy width and height, has one band, and that the image average is between 0 and 255. Here's how libvips tests text: https://github.com/libvips/libvips/blob/master/test/test-suite/test_create.py#L403-L418 |
Hi @jcupitt and thanks for your feedback, makes sense. Also, @lovell, after playing around with my version and testing, i think that having default values for width (0), height (0) and dpi (72) is not a good idea and makes the default behavior strange and different from vips (unless making some adjustments) For exemple, for the following commands (vips default behavior vs. sharp) :
I see 2 options :
I do think that the 1st option is better but would like to have your point of view on this. Also, here after getting the image from libvips, even if i set the image type manually to VIPS_INTERPRETATION_B_W, i always get a 3 channel image in sharp when testing (despite the image.bands() being equals to 1). I expected to have only one channel image with its space being 'b-w' and not 'srgb' when the rgba option is set to false. Sorry for all my questions and hope i made my self clear :-) Regards, |
287208e
to
e743c26
Compare
Hello, I just re-pushed with updated tests :
I'll wait for your review before doing any further changes. Regards, |
@brahima Thank you very much for the PR, I plan to review this next week. |
Hello @lovell, Thanks in advance for your time. I stay tuned :-) |
Any updates on this one? Would love to utilize this feature. |
Hi @lovell, Just rebased my last work on main branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for taking the time to work on this feature, it's looking really good, only a couple of small inline comments.
The tests appear to be failing on Linux due to a lack of fonts in the CI environment. Whilst adding fonts should be straightforward, it highlights that we need to do something (code? docs?) to catch this problem and aid Linux users. I imagine it'll be common in FaaS environments such as AWS Lambda that lack control over the OS, or minimal containers that don't install fonts by default.
I'm going to switch the base branch to the eagle
branch for inclusion in sharp v0.31.0, so you may need to rebase as there have been a couple of changes relating to the forthcoming libvips v8.13.0 upgrade.
Thanks again, this is an oft-requested feature and will be greatly appreciated by many.
} | ||
image = VImage::new_memory().text(const_cast<char *>(descriptor->textValue.data()), textOptions); | ||
image.get_image()->Type = image.guess_interpretation(); | ||
imageType = ImageType::RAW; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth reading out the autofit_dpi
/ autofitDpi
value and adding it to the info
object of the response? It might be useful for someone to know at what DPI a font was rendered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about the info object exposed via output options (toFile / toBuffer ...) ?
Also, libvips seems to set the autofit_dpi calculated on the options object
However, the VOption class have only setters and no getters (with a private Pair structure).
Any hints on how to access the computed option value ?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set a reference to the variable to assign the value to, eg.
->set("autofit_dpi", &output_dpi)
And it'll assign the value on return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jcupitt, ok makes sense. Way easier than what i was thinking about :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lovell Just pushed a commit with the autofitDdpi parameter added to the info output object.
Still need to add some lines to the documentation but waiting to know if the value is exposed at the right place.
Thanks
Hello @lovell and @kleisauke and thanks for the time you took reviewing my PR.
You're welcome :-)
About adding the fonts for the CI env, do you have specific packages in mind ? Regarding font problem detection :
Ok, done :-)
|
Thanks for the updates, it looks like there are a couple of linting errors.
I'm happy to write the documentation for the use of fonts after we merge this PR. There have been a few questions in the past about SVG font rendering too, so it would be good to get it all down in one place. |
Commit 254944f on the |
@lovell My bad ... should be fixed now. |
@lovell Hi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for all the updates, a couple of very minor inline comments and we're good to go.
I've added some documentation about font discovery via commit 3e327a5 |
@lovell also added 2 lines to api-output documentation regarding autofit dpi. Hope we're good to go but do not hesitate if you have any feedback. |
Thank you very much for working on and persisting with this PR, it will be included in v0.31.0. |
Hello @lovell ,
This a PR regarding the vips_text feature (#512)
Some notes about this PR :
Thanks for your insights on my modifications and any advice about my macos related problems regarding the tests.
Regards,
Brahim