Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wordwrapimagewriter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wordwrapimagewriter

ES6 JS class to write text onto image with word wrapping

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

wordwrapimagewriter

ES6 JS class to write text onto image with word wrapping

Installation

npm install wordwrapimagewriter --save

Usage

Write lines onto an image wrapping and automatically determining
spacing and padding as specified

// Instantiate the writer
var writer = new wordwrapimagewriter({
  imgFilename: './imageToWriteOnto.png',
  availableLines: 3, // your maximum line number you allow
  topPadPx: 50, // spacing from top of image to move down before writing
  lineBottomPadPx: 5, // spacing at bottom of each line
  fontFile: './HelveticaBold.ttf',
});

// Call open to asynchronously load image before writing
writer.openImg(() => {
  // The color declarations are from the node-gd package in rgba format
  var usernameColor = writer.img.colorAllocateAlpha(255, 20, 20, 1);
  var textColor = writer.img.colorAllocateAlpha(255, 255, 255, 1);
  var usernameText = "jenk37: ";
  var messageText = "I think that the wordwrapimagewriter is pretty good";

  // Write text onto the image. If the text takes more more lines
  // than availableLines, it will return the text that did not fit.
  var textThatWontFit = writer.writeText(usernameText, usernameColor);

  if (textThatWontFit) {
    console.log("[!] Text couldn't fit:", comment.username);
  }

  // Change font or size. Changing size will automatically update lineLength
  writer.setFontSize(30);
  writer.setFont('./Helvetica.ttf');

  textThatWontFit = writer.writeText(messageText, textColor);

  if (textThatWontFit) {
    console.log("[!] Text couldn't fit:", textThatWontFit);
  }

  // Save the image file
  writer.save("./newImageFilename.png", () => {
    return callback();
  });
});


Credits

http://c-cfalcon.rhcloud.com

Keywords

FAQs

Package last updated on 22 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc