simple_text autofit not left aligned
lawik opened this issue · comments
Lars Wikman commented
Default for autofit says it should be left-aligned: https://hexdocs.pm/image/Image.Text.html#simple_text/2
Image.Text.simple_text!("foo", width: 800, height: 120, autofit: true) |> Image.write!("foo.png")
Even when forced, no bueno:
Image.Text.simple_text!("foo", width: 800, height: 120, autofit: true, align: :left) |> Image.write!("foo.png")
Kip Cole commented
Good callout. This issue is a combination of this commit which is not yet in the published version and some more docs required to explain the difference between :align
and :x/:y
.
:align
is how multi-line text is aligned. For a single line of text that's going to be immaterial of course.:x
/:y
is how the text is placed on its background image. When image dimensions are specified (likewidth: 800, height: 120
)Image
guarantees that what is retuned is an image of exactly that size. The underlying text generation functions inlibvips
do not provide that guarantee so after the text is generated it is placed on a background image of exactly the right size. How the text is placed on that background is determined by:x
and:y
where the defaults arex: :center, y: :middle
.
Therefore if you:
- Add
{:image, github: "elixir-image/image"}
to yourdeps
mix deps.get
- And finally
Image.Text.simple_text!("foo", width: 800, height: 120, autofit: true, x: :left)
I think you will see what you expect.
@quentin-bettoum is doing some amazing work on webp
images and gif
s so as soon as we can merge all of that into the main branch and I can finish up the warp_perspective
function we can publish a new version. Objective is to do so this weekend.
Lars Wikman commented
Yup, works :)