Skip to content

Commit

Permalink
Fix image conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
qubyte committed Jan 30, 2022
1 parent fb832e1 commit eea9d1b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions functions/function-helpers/upload-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ import sharp from 'sharp';
import { upload } from './upload.js';

export async function uploadImage(photo) {
console.log('Converting image...', photo);

const time = Date.now();
const resized = sharp(photo.content).resize(800);
const [jpeg, avif, webp] = Promise.all([
resized.jpeg().toBuffer(),
resized.avif().toBuffer(),
resized.webp().toBuffer()
]);
const jpeg = await sharp(photo.content)
.resize(800)
.jpeg()
.toBuffer();
await upload('New photo (jpeg).\n\n[skip ci]', 'images', `${time}.jpeg`, jpeg);

const avif = await sharp(photo.content)
.resize(800)
.avif()
.toBuffer();
await upload('New photo (avif).\n\n[skip ci]', 'images', `${time}.avif`, avif);

const webp = await sharp(photo.content)
.resize(800)
.webp()
.toBuffer();
await upload('New photo (webp).\n\n[skip ci]', 'images', `${time}.webp`, webp);

return `/images/${time}.jpeg`;
Expand Down

0 comments on commit eea9d1b

Please sign in to comment.