This is a Client of the acrool-imgz api server, which can isolate its core from the impact of the environment version.
- Use axios as the driver for client requests
- Need to set up acrool imgz api server acrool/acrool-imgz-api
yarn add @acrool/imgz-client
use in your nodejs code:
import {ImgzNodeClient} from '@acrool/imgz-client';
const imgzClient = new ImgzNodeClient('http://localhost:8081');
const options = {
resize: {width: 500},
quality: 90,
};
const thumbOptions = {
resize: {width: 100},
quality: 80,
};
await imgzClient
.squashWebp(filePath)
.toSave(uploadIOThumbPath, thumbOptions)
.toSave(uploadIOPath, options)
.completeAll();
use in your browser frontend code:
import {ImgzClient} from '@acrool/imgz-client';
import {SubmitHandler, useForm} from 'react-hook-form';
interface IForm {
sourceFile: File
}
const Example = () => {
const HookForm = useForm<{sourceFile}>();
const handleSubmitHandler: SubmitHandler<IForm> = async formData => {
const imgzClient = new ImgzClient();
const options = {
resize: {width: 250},
quality: 90,
timeout: 10000, // Example timeout
};
await imgzClient
.squashWebp(formData.sourceFile[0], options)
.then(setBlobImg);
};
}