Create a url /memegen/api/write some text here
that generates an image meme.
Use the jimp library to help you draw text into the image.
Allow users to specify the following in the URL parameters:
Cache the last 10 images searched in memory so your server will return the images faster if it has been loaded before.
Example:
Using Jimp:
Jimp.loadFont(....)
takes in a font variable and returns a promise.
Jimp.FONT_SANS_32_WHITE
or ...BLACK.font
object.Jimp.read(...)
takes in a url and returns a promise
image
object.image.print
takes in a font object, starting x position, starting y position, and the text you want to write.image.getBuffer
takes in a fileType and returns a promise.
Jimp.MIME_JPEG
.buffer
object. You can turn the buffer into a string and call fs.writeFile
to create a meme file, but we don't want to create unnecessary files. We can simply send the buffer back as a response with res.send(buffer)
Make sure to set the response content-type
header to image/jpeg
before sending back the response!