npm package: @stack-soumik/watermarkimage
Description: A simple tool to process images with a watermark using Sharp
Author: Soumik Sarkar
Latest version: 1.0.1

## Usage

### Basic Watermarking

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

```jsx
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:

```jsx
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**:

```jsx
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:

```jsx
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

```jsx
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

```jsx
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
    bash
    Copy code
    git checkout -b feature/your-feature-name
    
    ```
    
3. **Make your changes** and commit them:
    
    ```bash
    bash
    Copy code
    git commit -m 'Add some feature'
    
    ```
    
4. **Push to your branch**:
    
    ```bash
    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:

- **Author**: Soumik Sarkar
- **Email**: ratulsarkar216@gmail.com