Crate rofl [−] [src]
Lulz on demand!
This here rofl
crate, aptly named, is capable of the extraordinary feat
of putting text on images. And not just still images: it does cover animated GIFs as well!
In other words, the crate can be used to create memes, which purists generally refer to as image macros.
Much example
extern crate rofl; let engine = rofl::Engine::new("data/templates", "data/fonts"); let image_macro = rofl::ImageMacro { template: "zoidberg".into(), captions: vec![ rofl::Caption::text_at(rofl::VAlign::Top, "Need an example?"), rofl::Caption::text_at(rofl::VAlign::Bottom, "Why not Zoidberg?"), ], ..rofl::ImageMacro::default() }; let output = engine.caption(image_macro)?; let mut file = fs::OpenOptions::new().write(true).open("zoidberg.png")?; file.write_all(&*output)?;
Very concepts
To create memes, you need two types of media resources (in addition to impeccable wit):
- templates -- named images & animated GIFs that we can put text on
- fonts to render the text with (like
"Impact"
or"Comic Sans"
)
Those resources have to be provided to the captioning Engine
.
In the simple above, they are just files contained within some directories.
If you're doing something more complicated --
like a website where users can upload their own images --
you can implement your own Loader
s for templates or even fonts.
A meme is defined by the ImageMacro
structure.
These can be deserialized from JSON or query strings if desired.
Wow
Go forth and meme!
Modules
animated_gif |
Module handling the decoding & encoding of animated GIFs. |
cache |
Module implementing a thread-safe LRU cache. |
Structs
BytesLoader |
Wrapper around |
CachingLoader |
A loader that keeps a cache of resources previously loaded. |
Caption |
Describes a single piece of text rendered on the image macro. |
CaptionOutput |
Output of the captioning process. |
Color |
RGB color of the text. |
Engine |
Image captioning engine. |
FileLoader |
Loader for files in given directory. |
Font |
Font that can be used to caption image macros. |
FontLoader |
Loader for fonts stored in a directory. |
HAligns | |
ImageMacro |
Describes an image macro. Used as an input structure. |
TemplateLoader |
Loader for templates stored in a directory. |
VAligns |
Enums
CaptionError |
Error that may occur during the captioning. |
FontError |
Error that may occur during font load. |
HAlign |
Horizontal alignment of text within a rectangle. |
Template |
Represents an image macro template. |
TemplateError |
Error that may occur during template load. |
VAlign |
Vertical alignment of text within a rectangle. |
Constants
DEFAULT_COLOR |
Default color of the text. |
DEFAULT_FONT |
Name of the default font. |
DEFAULT_HALIGN |
Default horizontal alignment of text. |
DEFAULT_IMAGE_FORMAT |
Default image format to use when encoding image macros. |
DEFAULT_OUTLINE_COLOR |
Default color of the text outline.
This is the inversion of |
FONT_FILE_EXTENSION |
File extension of font files. |
MAX_CAPTION_COUNT |
Maximum number of captions an ImageMacro can have. |
MAX_CAPTION_LENGTH |
Maximum length (in Unicode codepoints) of a single caption text. |
MAX_HEIGHT |
Maximum height of the result image. |
MAX_WIDTH |
Maximum width of the result image. |
Traits
Loader |
Loader of resources from some external source. |
Type Definitions
SharingLoader |
Type of a loader that doles out shared references to the resources. |