Comments (1)
It's not clean (I'm not a JS expert), but it works (by using withMetadata()
https://sharp.pixelplumbing.com/api-output#withmetadata)
#!/usr/bin/env node
const fs = require("fs");
const prettyBytes = require("pretty-bytes");
const sharp = require("sharp");
if (process.argv.length !== 5) {
console.error("usage: bespoke file.jpg name true|false");
process.exit(0);
}
const inputBuffer = fs.readFileSync(process.argv[2]);
const name = process.argv[3];
const keepExif = process.argv[4];
const today = new Date();
const prefix = `${today.getFullYear()}-${(today.getMonth() + 1)
.toString()
.padStart(2, "0")}-${today.getDate().toString().padStart(2, "0")}-${name}`;
fs.renameSync(process.argv[2], `${prefix}_original.jpg`);
(async function () {
for (let res of [128, 640, 1280, 2880]) {
const jpgOutputFilename = `${prefix}_${res}.jpg`;
const webpOutputFilename = `${prefix}_${res}.webp`;
if (keepExif == "true") {
await sharp(inputBuffer).withMetadata().resize(res).toFile(jpgOutputFilename);
await sharp(inputBuffer).withMetadata().resize(res).toFile(webpOutputFilename);
} else {
await sharp(inputBuffer).resize(res).toFile(jpgOutputFilename);
await sharp(inputBuffer).resize(res).toFile(webpOutputFilename);
}
console.log(
`${res}x webp ${prettyBytes(
fs.readFileSync(webpOutputFilename).byteLength
)}`
);
console.log(
`${res}x jpg ${prettyBytes(
fs.readFileSync(jpgOutputFilename).byteLength
)}`
);
}
})();
from bespoke.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bespoke.