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

pixmix

v1.0.4

Published

🖼️ PixMix - An intuitive image composer.

Downloads

4

Readme

🖼️ PixMix

A robust and intuitive image manipulation library for Node.js, designed to superimpose text and images onto a base image.

🚀 Installation

You can install the PixMix package using npm:

npm install pixmix

🛠️ Usage

To utilize PixMix, import the package, create an instance with a source image, and use methods to add text or other images, then save the result:

const PixMix = require('pixmix');

const image = new PixMix('source.jpg');
await image.addImage({ image: 'overlay.png', top: 30, left: 50 });
image.addText({
    text: 'Sample Text Here',
    ttf: 'path/to/font.ttf',
    size: 24,
    color: 'white',
    x: 100,
    y: 150
});
await image.toFile('output.jpg');
  • Check de demo: https://github.com/clasen/PixMix/blob/master/demo

📚 API

new PixMix(sourceImagePath)

Creates a new instance of the PixMix class for image manipulation.

  • Parameters:
    • sourceImagePath (string): Path to the source image file that will serve as the base for further editing.

addText(options)

Adds text to the image using SVG format. The method adjusts the text's properties and positions it on the image according to the specified options.

  • Parameters:
    • options (object): Configuration for adding text. The object includes:
      • text (string): The text content to add to the image.
      • ttf (string): Path to the TrueType font file (.ttf) used for rendering the text.
      • size (number): Font size for the text.
      • color (string): Color of the text, specified in any CSS color format (e.g., hex, rgba).
      • x (number): The x-coordinate (horizontal position) for the text's starting point on the image.
      • y (number): The y-coordinate (vertical position) for the text's starting point on the image.
      • anchor (string, optional): Text anchor position (e.g., 'top left', 'middle', 'bottom right'), defaults to 'top left'.
      • letterSpacing (number, optional): Space between the characters, defaults to 0.
      • lineHeight (number, optional): Line height expressed as a multiplier of the font size, defaults to 1.2.
  • Returns: Adds a text overlay to the image composition queue.

addImage(options)

Adds another image as a layer on top of the base image.

  • Parameters:
    • options (object): Configuration for adding an overlay image. The object includes:
      • image (string): Path to the image file or a Buffer containing image data.
      • top (number): The top position (y-coordinate) where the overlay image will be placed on the base image.
      • left (number): The left position (x-coordinate) where the overlay image will be placed on the base image.
  • Returns: Adds an image overlay to the image composition queue.

toFile(outputImagePath)

Saves the composited image to a file.

  • Parameters:
    • outputImagePath (string): The path where the final composited image will be saved.
  • Returns: Asynchronously saves the composited image to a file. This method returns a Promise that resolves when the file has been written.

toBuffer()

Generates a Buffer of the composited image, suitable for use when images need to be used directly in memory rather than saved to disk.

  • Returns: Asynchronously returns a Buffer of the composited image. This method returns a Promise that resolves with the Buffer.

🤝 Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

📄 License

The MIT License (MIT)

Copyright (c) Martin Clasen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.