elixir-image/image

simple_text autofit not left aligned

lawik opened this issue · 3 comments

lawik 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")

foo

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 (like width: 800, height: 120) Image guarantees that what is retuned is an image of exactly that size. The underlying text generation functions in libvips 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 are x: :center, y: :middle.

Therefore if you:

  1. Add {:image, github: "elixir-image/image"} to your deps
  2. mix deps.get
  3. 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 gifs 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.

@lawik let me know if the suggestion above solves your issue?

lawik commented

Yup, works :)