Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/landing/imagecompressor/src/ |
Upload File : |
import {Type} from 'main.core'; import Compressor from 'compressorjs/src/index'; import allowedSizeProps from './internal/allowed-size-props'; import urlToBlob from './internal/url-to-blob'; import type {ImageCompressorOptions} from './types'; export class ImageCompressor { static maxOriginalPngSize = 5 * 1024 * 1024; constructor(file, options: ImageCompressorOptions = {}) { this.file = file; this.options = {quality: 0.8, ...options}; if (this.options.retina) { allowedSizeProps.forEach((prop) => { if (Type.isNumber(this.options[prop])) { this.options[prop] *= 2; } }); } } static compress(file, options: ImageCompressorOptions = {}): Promise<File> { return urlToBlob(file) .then((blob) => { if (Type.isStringFilled(blob.type)) { if ( blob.type.includes('gif') || ( blob.type.includes('png') && blob.size < ImageCompressor.maxOriginalPngSize ) ) { return blob; } } const compressor = new ImageCompressor(blob, options); return compressor.compress(); }); } compress(): Promise<File> { return new Promise((resolve, reject) => { void new Compressor( this.file, {...this.options, ...{success: resolve, error: reject}}, ); }); } }