cjs/index.js
function createPng(pixelData) {
	const length = pixelData.length + 4 - (pixelData.length % 4);
	const pixels = Math.ceil(length / 4);
	const width = Math.min(pixels, MAX_WIDTH);
	const height = Math.ceil(pixels / MAX_WIDTH);
	const bytesPerRow = width * 4;
	const buffer$$1 = buffer.Buffer.alloc((bytesPerRow + 1) * height);

	// Write pixel data to buffer
	for (let y = 0; y < height; y += 1) {
		const offset = y * bytesPerRow;
		const rowData = pixelData.slice(offset, offset + bytesPerRow);
		const rowStartX = offset + y + 1;
		const rowEndX = rowStartX + bytesPerRow;

		buffer$$1.writeUInt8(0, offset + y);
		buffer$$1.fill(rowData, rowStartX, rowEndX);
	}

	return new Promise((resolve, reject) => {
		zlib.deflate(buffer$$1, (error, deflated) => {
			if (error) {
				reject(error);
				return;
			}

			resolve(buffer.Buffer.concat([
				PNG_HEADER,
				createIHDRChunk(width, height),
				createIDATChunk(deflated),
				createIENDChunk(),
			]));
		});
	});
}
function createPng(pixelData) {
	const length = pixelData.length + 4 - (pixelData.length % 4);
	const pixels = Math.ceil(length / 4);
	const width = Math.min(pixels, MAX_WIDTH);
	const height = Math.ceil(pixels / MAX_WIDTH);
	const bytesPerRow = width * 4;
	const buffer$$1 = buffer.Buffer.alloc((bytesPerRow + 1) * height);

	// Write pixel data to buffer
	for (let y = 0; y < height; y += 1) {
		const offset = y * bytesPerRow;
		const rowData = pixelData.slice(offset, offset + bytesPerRow);
		const rowStartX = offset + y + 1;
		const rowEndX = rowStartX + bytesPerRow;

		buffer$$1.writeUInt8(0, offset + y);
		buffer$$1.fill(rowData, rowStartX, rowEndX);
	}

	return new Promise((resolve, reject) => {
		zlib.deflate(buffer$$1, (error, deflated) => {
			if (error) {
				reject(error);
				return;
			}

			resolve(buffer.Buffer.concat([
				PNG_HEADER,
				createIHDRChunk(width, height),
				createIDATChunk(deflated),
				createIENDChunk(),
			]));
		});
	});
}
function createPng ( pixelData ) { const length = pixelData . length + 4 - ( pixelData . length % 4 ) ; const pixels = Math . ceil ( length / 4 ) ; const width = Math . min ( pixels , MAX_WIDTH ) ; const height = Math . ceil ( pixels / MAX_WIDTH ) ; const bytesPerRow = width * 4 ; const buffer$$1 = buffer . Buffer . alloc ( ( bytesPerRow + 1 ) * height ) ; // Write pixel data to buffer for ( let y = 0 ; y < height ; y += 1 ) { const offset = y * bytesPerRow ; const rowData = pixelData . slice ( offset , offset + bytesPerRow ) ; const rowStartX = offset + y + 1 ; const rowEndX = rowStartX + bytesPerRow ; buffer$$1 . writeUInt8 ( 0 , offset + y ) ; buffer$$1 . fill ( rowData , rowStartX , rowEndX ) ; } return new Promise ( ( resolve , reject ) => { zlib . deflate ( buffer$$1 , ( error , deflated ) => { if ( error ) { reject ( error ) ; return ; } resolve ( buffer . Buffer . concat ( [ PNG_HEADER , createIHDRChunk ( width , height ) , createIDATChunk ( deflated ) , createIENDChunk ( ) , ] ) ) ; } ) ; } ) ; }
Create a png from the given pixel data.

@param pixelData
@returns {Promise<Buffer>}
Create a png from the given pixel data .