elixir-image/image

Meme Generator Text

GenericJam opened this issue · 14 comments

Given that this lib is focused on ease of use and picking good defaults I'd suggest the meme template as a good place to look for good defaults. With memes, as they're essentially disposable one doesn't spend a lot of time on design.

image

Text:
White by default with option for something else
Font:
Wide sanserif by default

Function receives a list of bounding boxes with top x, y coordinates. Possibly just percentages instead of pixels as the images may be varying sizes.
Font is sized to fill up the bounding box and is centered by default.

Check to see if the given bounding box actually fits on the image? This is where percentages may be superior.

Interesting idea. Text handling, especially wrapping and sizing to fit, isn't especially easy but I'll give it a go over the weekend. Keep the idea coming (no guarantees I'll tackle them all, but so far Image is still a lot of fun).

Thanks to your suggestion I've got this far:

Image.open!("./test/support/images/meme.jpg") 
|> Image.meme!("One simply cannot", text: "Enjoy image processing without libvips") 
|> Image.preview

image

This is cool!
Default font shows up as stars on Linux.

image

Also, what fonts are supported? Is this a vips tihng or are they system fonts?

Image version 0.13.0 includes a meme generator. I put an example in the accouncement on Elixir Forum. Open to additional suggestions for sure. But for now I'll close the issue as "done". I'm enjoying your "challenges" so keep them coming. And feel free to reopen the issue if there's something I've missed.

Ahhhhh, I did wonder about cross-platform font naming. I have the default set to "Impact" since that seems to be the go-to. I don't have a Linux machine handy. Any chance you could "fc-list | grep Imact" to see if its installed? Definitely open to suggestions.

An empty string makes it letters at least.

I guess that means it resolves to a default font (and not a great one at that!)

BTW, in Livebook 0.17 there is automatically an image preview of images if you have Kino as a dependency.

Comes back empty for Impact.

I was thinking of including Impact.ttf int he package and loading that if the font name is "Impact". Would that make sense?

I think including the default makes sense as you can never know for sure what people are going to have on their system.
I was thinking of using this to do an online meme generator where they could include a webfont as one of the args. That's the was on the web to guarantee a font is present.

Also Geneva and Tahoma seem like decent alternatives on my system if you want to have a fall back. Does vips just choose the last on the list? It's weird to me that none specified gives one result, an empty string gives another and a string with nonsense yet another.

If you're following rules a la CSS. specifying a good last resort alternative like 'sanserif' would be sensible.

The underlying text generation uses gtk I think and I have limited control over font handling. Basically I can specify a font family name but no fallbacks (so no CSS-like handling). I'll add the Impact.ttf file to the package and load it if Impact is the font specified. And make a note that a font needs to be in the list of fc-list. Lastly, I'll add a parameter to take a font file name.

Thanks! Great job!

I've updated the code on GitHub to take a :font_file option. If the font name is Impact then it will use the font file that is now included in the repo. It seems to operate correctly on a Mac.

If you're feeling generous perhaps you could try in on your Linux machine? Just:

def deps do
  [
    {:image, github: "kipcole9/image"},
    ...
  ]
end

Working now!
image