https://github.com/samsyntx/image-setter
Image Setter is a lightweight npm package that simplifies the process of compressing and converting image, making it easy to optimize and manipulate various IMage formats effortlessly.
https://github.com/samsyntx/image-setter
compressor image image-processing image-setter imagecompression imagetools pngtojpg
Last synced: about 1 year ago
JSON representation
Image Setter is a lightweight npm package that simplifies the process of compressing and converting image, making it easy to optimize and manipulate various IMage formats effortlessly.
- Host: GitHub
- URL: https://github.com/samsyntx/image-setter
- Owner: samsyntx
- Created: 2024-01-29T17:12:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-23T16:35:46.000Z (over 2 years ago)
- Last Synced: 2024-04-24T13:36:11.112Z (about 2 years ago)
- Topics: compressor, image, image-processing, image-setter, imagecompression, imagetools, pngtojpg
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/image-setter
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Media Toolkit
A versatile npm package providing functionalities to compress, convert file formats, and handle multimedia content seamlessly.
### Installation
```
npm install image-setter
```
## Usage
### compressAndConvertToJPEG
This function compresses and converts an image file to JPEG format based on the specified settings.
```
import { compressAndConvertToJPEG } from 'image-setter';
const file = /* your File object */;
const settings = {
toWidth: 300,
toHeight: 300,
quality: 0.6,
maxSize: 100 * 1024,
};
compressAndConvertToJPEG({ file, settings })
.then((compressedBlob) => {
// Handle the compressed Blob as needed
})
.catch((error) => {
console.error('Error:', error);
});
```
### convertFileFormat
This function converts the file format of a given file.
```
import { convertFileFormat } from 'image-setter';
const file = /* your File object */;
const targetFormat = 'image/png';
convertFileFormat({ file, targetFormat })
.then((convertedBlob) => {
// Handle the converted Blob as needed
})
.catch((error) => {
console.error('Error:', error);
});
```
### base64ToBinary
Converts a base64-encoded string to a Uint8Array.
```
import { base64ToBinary } from 'image-setter';
const base64String = /* your base64-encoded string */;
const binaryData = base64ToBinary(base64String);
// Use binaryData as needed
```
### convertToBase64
Converts a File object to a base64-encoded string.
```
import { convertToBase64 } from 'image-setter';
const file = /* your File object */;
convertToBase64(file)
.then((base64String) => {
// Handle the base64-encoded string as needed
})
.catch((error) => {
console.error('Error:', error);
});
```
### fileAsArrayBuffer
Converts a Compressed Image into Binary string.
```
import { fileAsArrayBuffer } from 'image-setter';
const file = /* your Image File */;
fileAsArrayBuffer(file)
.then((bufferData) => {
// Handle the bufferData string as needed
})
.catch((error) => {
console.error('Error:', error);
});
```