smartjimp/readme.md

106 lines
4.8 KiB
Markdown
Raw Permalink Normal View History

2023-11-24 19:08:48 +00:00
# @push.rocks/smartjimp
2020-02-02 20:10:42 +00:00
a tool fr working with images in TypeScript
2020-02-01 17:24:41 +00:00
2024-04-14 15:44:47 +00:00
## Install
To install `@push.rocks/smartjimp`, use the following command in your project directory:
```bash
npm install @push.rocks/smartjimp --save
```
2020-02-01 17:24:41 +00:00
## Usage
2020-02-02 20:10:42 +00:00
2024-04-14 15:44:47 +00:00
`@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:
```typescript
import { SmartJimp } from '@push.rocks/smartjimp';
```
Next, create an instance of `SmartJimp` by specifying the preferred image processing mode (`sharp` or `jimp`):
```typescript
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.
```typescript
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.
```typescript
// 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:
```typescript
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.
## License and Legal Information
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](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.
2020-02-02 20:10:42 +00:00
2024-04-14 15:44:47 +00:00
### Company Information
2020-02-02 20:10:42 +00:00
2024-04-14 15:44:47 +00:00
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
2020-02-02 20:10:42 +00:00
2024-04-14 15:44:47 +00:00
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
2020-02-01 17:24:41 +00:00
2024-04-14 15:44:47 +00:00
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.