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

@stack-soumik/watermarkimage

v1.0.1

Published

A simple tool to process images with a watermark using Sharp

Downloads

127

Readme

Usage

Basic Watermarking

To add a watermark to an image and save it in the default output directory, use the following code:

javascript
Copy code
import { processImageWithWatermark } from '@stack-soumik/waterMarkImage';

const inputPath = './path/to/your/image.jpg'; // Path to your input image
const watermarkPath = './path/to/your/watermark.png'; // Path to your watermark

processImageWithWatermark(inputPath, watermarkPath)
    .then(result => {
        console.log('Watermarked image saved at:', result.outputPath);
    })
    .catch(error => {
        console.error('Error processing image:', error);
    });

Custom Output Directory

You can also specify a custom directory for the output files:

javascript
Copy code
const customOutputDir = './path/to/custom/output/';

processImageWithWatermark(inputPath, watermarkPath, customOutputDir)
    .then(result => {
        console.log('Watermarked image saved at:', result.outputPath);
    })
    .catch(error => {
        console.error('Error processing image:', error);
    });

API Reference

processImageWithWatermark(inputPath: string, watermarkPath: string, outputPath?: string)

  • inputPath: string - The path to the input image that you want to watermark.
  • watermarkPath: string - The path to the watermark image you wish to overlay on the input image.
  • outputPath: string (Optional) - The path to the directory where the processed image will be saved. If not provided, the default output directory will be used.

Returns: A Promise that resolves with an object containing:

  • outputPath: The path where the watermarked image is saved.
  • fileName: The name of the saved file.

Example:

javascript
Copy code
const result = await processImageWithWatermark('./image.jpg', './watermark.png');
console.log(result.outputPath); // Outputs: path/to/default/output/image-watermarked.jpg

Error Handling

The package is designed to handle common errors, such as missing files or invalid paths. If an error occurs, it will reject the promise with an appropriate error message.

Example:

javascript
Copy code
try {
    await processImageWithWatermark('invalid.jpg', watermarkPath);
} catch (error) {
    console.error('Failed to process image:', error.message); // Will log the error message
}

Examples

1. Basic Watermarking

javascript
Copy code
import { processImageWithWatermark } from '@stack-soumik/waterMarkImage';

(async () => {
    const inputPath = './image.jpg';
    const watermarkPath = './watermark.png';

    try {
        const result = await processImageWithWatermark(inputPath, watermarkPath);
        console.log('Watermarked image saved at:', result.outputPath);
    } catch (error) {
        console.error('Error:', error.message);
    }
})();

2. Custom Output Directory

javascript
Copy code
import { processImageWithWatermark } from '@stack-soumik/waterMarkImage';

(async () => {
    const inputPath = './image.jpg';
    const watermarkPath = './watermark.png';
    const customOutputDir = './custom-output/';

    try {
        const result = await processImageWithWatermark(inputPath, watermarkPath, customOutputDir);
        console.log('Watermarked image saved at:', result.outputPath);
    } catch (error) {
        console.error('Error:', error.message);
    }
})();

Contributing

We welcome contributions to improve this package! Here’s how you can help:

  1. Fork the repository on GitHub.

  2. Create a new branch for your feature or bug fix:

    bash
    Copy code
    git checkout -b feature/your-feature-name
       
  3. Make your changes and commit them:

    bash
    Copy code
    git commit -m 'Add some feature'
       
  4. Push to your branch:

    bash
    Copy code
    git push origin feature/your-feature-name
       
  5. Open a pull request.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Contact

For any questions or feedback, feel free to reach out: