HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/node_modules/imagemin-optipng/index.js
'use strict';
const execBuffer = require('exec-buffer');
const isPng = require('is-png');
const optipng = require('optipng-bin');

module.exports = options => async buffer => {
	options = {
		optimizationLevel: 3,
		bitDepthReduction: true,
		colorTypeReduction: true,
		paletteReduction: true,
		interlaced: false,
		errorRecovery: true,
		...options
	};

	if (!Buffer.isBuffer(buffer)) {
		throw new TypeError('Expected a buffer');
	}

	if (!isPng(buffer)) {
		return buffer;
	}

	const arguments_ = [
		'-strip',
		'all',
		'-clobber',
		'-o',
		options.optimizationLevel,
		'-out',
		execBuffer.output
	];

	if (options.errorRecovery) {
		arguments_.push('-fix');
	}

	if (!options.bitDepthReduction) {
		arguments_.push('-nb');
	}

	if (typeof options.interlaced === 'boolean') {
		arguments_.push('-i', options.interlaced ? '1' : '0');
	}

	if (!options.colorTypeReduction) {
		arguments_.push('-nc');
	}

	if (!options.paletteReduction) {
		arguments_.push('-np');
	}

	arguments_.push(execBuffer.input);

	return execBuffer({
		input: buffer,
		bin: optipng,
		args: arguments_
	});
};