allow disproportionate memes

This commit is contained in:
2026-05-09 13:37:20 -03:00
parent e5fa16a88d
commit ff3db71084
8 changed files with 31 additions and 35 deletions
+13 -14
View File
@@ -40,28 +40,27 @@ test('rejects gif uploads', () => {
);
});
test('rejects non-square images when square uploads are required', () => {
test('accepts non-square png uploads', () => {
const png = encodePng(32, 24, () => [0, 255, 65, 255]);
assert.throws(
() => validateImage(png, {
maxBytes: 5 * 1024 * 1024,
maxWidth: 6000,
maxHeight: 6000,
maxPixels: 20_000_000,
requireSquare: true
}),
/square/
);
const image = validateImage(png, {
maxBytes: 5 * 1024 * 1024,
maxWidth: 6000,
maxHeight: 6000,
maxPixels: 20_000_000
});
assert.equal(image.width, 32);
assert.equal(image.height, 24);
});
test('normalizes png uploads to square webp', async () => {
const png = encodePng(32, 32, () => [0, 255, 65, 255]);
test('normalizes png uploads to webp while preserving aspect ratio', async () => {
const png = encodePng(32, 24, () => [0, 255, 65, 255]);
const normalized = await normalizeToWebp(png);
assert.equal(normalized.image.mime, 'image/webp');
assert.equal(normalized.image.ext, 'webp');
assert.equal(normalized.image.width, 32);
assert.equal(normalized.image.height, 32);
assert.equal(normalized.image.height, 24);
assert.equal(normalized.buffer.subarray(0, 4).toString('ascii'), 'RIFF');
assert.equal(normalized.buffer.subarray(8, 12).toString('ascii'), 'WEBP');
});