Meme Gen

Demo Link

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:

  • blur - (Optional). Amount of pixels to blur by.
  • src - (Optional). URL for the meme image. If no url is provided, use https://placeimg.com/640/480/any
  • black - (Optional). If true, draws the text in the image in black. Otherwise, white.

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.
    • For font, you can use a built in font like Jimp.FONT_SANS_32_WHITE or ...BLACK.
    • When the promise resolves, you get a font object.
  • Jimp.read(...) takes in a url and returns a promise
    • When the promise resolves, you get a image object.
  • Using your image object you can run these functions:
    • 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.
      • For fileType, you can use the built in type Jimp.MIME_JPEG.
      • When the promise resolves, you get a 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!