AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.15.188.93
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/bitrix/www/bitrix/js/landing/imagecompressor/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/bitrix/www/bitrix/js/landing/imagecompressor/src/imagecompressor.js
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}},
			);
		});
	}
}

Anon7 - 2022
AnonSec Team