npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

caption

v0.1.1

Published

A captioned image generator for node.js, using imagemagick libraries.

Downloads

8

Readme

node-caption

Node utility for captioning images via imageMagick

To use node-caption, the system it's running on must have imageMagick (and ghostscript) installed. Here are some ways to do that:

OSX: brew install imagemagick ghostscript

Ubuntu: apt-get install imagemagick ghostscript

RedHat and other yummy systems yum install imagemagick ghostscript

additionally, you can install it from a binary, as described here http://www.imagemagick.org/script/binary-releases.php

or build from source: http://www.imagemagick.org/script/install-source.php

Usage:

To use caption in a node project, just require it:

var caption = require('caption')

There are only two methods in caption, path, and url

To caption an existing image file, do this:

caption.path("path/to/file.jpg",options,function(err,captionedImage){
  // err will contain an Error object if there was an error
  // otherwise, captionedImage will be a path to a file.
})

To download the image first, use caption.url:

caption.url("http://www.someImageHost.com/path/to/image.jpg",options,function(err,captionedImage){
  // err will contain an Error object if there was an error
  // otherwise, captionedImage will be a path to a file.
})

the options object is always the same, and has the following options:

  • caption : A string containing the text you would like to caption the image with
  • bottomCaption : A string containing the bottom caption, for a meme style caption
  • outputFile : if specified, caption will put the new image in this file. If not, it'll return an image in the /tmp directory.
  • minHeight : minimum height of the image. (defaults to 100)
  • minWidth : minimum width of the image. (defaults to 500)
Command line

You can also use caption from the command line.

First, install caption:

npm install -g caption

then you can start generating images to your hearts content. Calling caption with no arguments will output the usage options:

Usage:
For a caption on the bottom of the image:
  caption <path to image or image url> -c "caption text" -o [ouput file]
For top and bottom captions (meme style):
  caption <path to image or image url> --top-caption "top caption" --bottom-caption "bottom caption" --output [ouput file]

The available options are:

-c / --caption / -b / --bottom-caption : caption text to put at the bottom of the image.

-t / --top : caption text to put at the top of the image. May not be used with out a bottom caption.

-o / --output : output file to render the image to.

The first argument is the path or URL to an image. You can use a url or a path, caption will try to download the url if it doesn't exist on your local fs.

To specify a minimum height or width from the command line, you can set the CAPTION_MIN_WIDTH and CAPTION_MIN_HEIGHT environment variables.

Examples:
caption http://simonbisleygallery.com/art/biz00157.jpg "I AM THE LAW" dredd.jpg

or

caption.url("http://simonbisleygallery.com/art/biz00157.jpg",{
  caption : "I AM THE LAW",
  outputFile : "dredd.jpg"
},function(err,filename){
  // do stuff
})

I AM THE LAW

caption http://i.imgur.com/AtLeN.png "You are mistaken." "This is my bowl." cat.jpg

or

caption.url("http://i.imgur.com/AtLeN.png",{
  caption : "You are mistaken.",
  bottomCaption : "This is my bowl.",
  outputFile : "cat.jpg"
},function(err,filename){
  // do stuff
})

This is my bowl.

Notes

Currently caption always uses white text with a 2px black stroke. It will automatically make the text as big as possible given the image.

In the future, I may add support for specifying certain imagemagick options for more versatility.

If you find issues, please let me know! The preferred method is to use the github issue tracker

Credit to Zach Holman's Fuck Yeah for inspiration.

Feel free to talk to me on Twitter - @jesseditson