A TypeScript library for image processing combining both sharp and jimp libraries.
Go to file
2024-05-29 14:13:46 +02:00
.gitea/workflows fix(core): update 2023-11-24 20:21:12 +01:00
.vscode fix(core): update 2023-01-09 18:17:33 +01:00
test fix(core): update 2023-12-03 23:09:48 +01:00
ts fix(core): update 2024-02-14 01:56:00 +01:00
.gitignore fix(core): update 2023-01-09 18:17:33 +01:00
.gitlab-ci.yml fix(core): update 2023-01-09 18:17:33 +01:00
license fix(core): update 2020-02-01 17:24:41 +00:00
npmextra.json update tsconfig 2024-04-14 17:44:47 +02:00
package.json update description 2024-05-29 14:13:46 +02:00
pnpm-lock.yaml fix(core): update 2024-02-14 01:56:00 +01:00
readme.hints.md update tsconfig 2024-04-14 17:44:47 +02:00
readme.md update tsconfig 2024-04-14 17:44:47 +02:00
tsconfig.json fix(core): update 2023-11-24 20:08:48 +01:00

@push.rocks/smartjimp

a tool fr working with images in TypeScript

Install

To install @push.rocks/smartjimp, use the following command in your project directory:

npm install @push.rocks/smartjimp --save

Usage

@push.rocks/smartjimp is a comprehensive TypeScript library for handling image processing with ease and efficiency. It leverages powerful image processing libraries such as sharp and jimp, providing a unified interface for performing common image manipulation tasks. This documentation aims to guide you through the installation and various functionalities of @push.rocks/smartjimp, ensuring you have the knowledge to integrate image processing capabilities into your TypeScript project effectively.

Getting Started

First, import the SmartJimp class from the package:

import { SmartJimp } from '@push.rocks/smartjimp';

Next, create an instance of SmartJimp by specifying the preferred image processing mode (sharp or jimp):

const imageProcessor = new SmartJimp({ mode: 'sharp' });

Processing Images

From Buffer

You can process images from a buffer. This is particularly useful when you have image data already available in your application, such as uploaded images.

import { SmartFile } from '@push.rocks/smartfile';

// Assuming you have an image buffer `imageBuffer`
let imageBuffer: Buffer;

// Convert the buffer to a SmartFile instance
const smartfileInstance = await SmartFile.fromBuffer(imageBuffer);

// Process the image, for example, resizing it to width 500px
const resizedImageBuffer = await imageProcessor.getFromSmartfile(smartfileInstance, {
  width: 500,
});

Creating Specific Formats

@push.rocks/smartjimp supports creating images in various formats, including AVIF, WebP, and PNG.

// For forcing a format, specify the `format` in the options, like 'png'
const pngBuffer = await imageProcessor.getFromSmartfile(smartfileInstance, {
  width: 500,
  format: 'png',
});

Advanced Image Manipulation

Inversion

You can invert the colors of an image as follows:

const invertedImageBuffer = await imageProcessor.getFromSmartfile(smartfileInstance, {
  invert: true,
});

Performance and Caching

@push.rocks/smartjimp employs caching mechanisms to enhance performance. Caching is handled internally, ensuring that repeated processing requests for the same image and settings are served faster by retrieving the processed image from the cache.

Mode: Sharp vs. Jimp

  • Sharp: Recommended for performance-critical applications. It is faster and supports a broader range of image formats. However, it relies on native libraries, which may need additional setup in certain environments.
  • Jimp: A pure JavaScript image processing library. While not as fast as Sharp, it guarantees compatibility across all Node.js environments without the need for additional native dependencies.

Conclusion

@push.rocks/smartjimp makes image processing in TypeScript applications highly accessible and efficient. Whether you need to resize, convert formats, or perform other image manipulations, @push.rocks/smartjimp provides a powerful yet simple API to accomplish these tasks with minimal effort. By abstracting away the complexities of direct interactions with libraries like sharp and jimp, it allows developers to focus more on building the core features of their applications.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.