imagsharp
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -31,5 +31,6 @@ #!/usr/bin/env node | ||
program.option("-w, --width [width]", "The width of the picture"); | ||
program.option("-s, --scale [scale]", "The scale of the picture"); | ||
program.option("-f, --format [format]", "The media type of the picture"); | ||
program.option("-q, --quality [quality]", "Picture quality", "80"); | ||
const edit = (imgPath, pathObj, dir, _width, quality, _format) => __awaiter(void 0, void 0, void 0, function* () { | ||
const edit = (imgPath, pathObj, dir, _width, scale, quality, _format) => __awaiter(void 0, void 0, void 0, function* () { | ||
const ext = pathObj.ext; | ||
@@ -45,3 +46,3 @@ let sharpOptions; | ||
const metadata = yield img.metadata(); | ||
const width = _width || metadata.width; | ||
const width = Math.round((_width || metadata.width) * scale); | ||
const name = pathObj.name; | ||
@@ -143,2 +144,9 @@ const format = _format || ext.slice(1); | ||
} | ||
let scale = 1; | ||
if (typeof opts.scale === "string" && opts.scale.length > 0) { | ||
const _scale = parseFloat(opts.scale); | ||
if (!isNaN(_scale)) { | ||
scale = _scale; | ||
} | ||
} | ||
let quality = 0; | ||
@@ -154,3 +162,3 @@ if (typeof opts.quality === "string" && opts.quality.length > 0) { | ||
} | ||
edit(imgPath, pathObj, dir, width, quality, opts.format).finally(() => { | ||
edit(imgPath, pathObj, dir, width, scale, quality, opts.format).finally(() => { | ||
progressBar.tick(); | ||
@@ -157,0 +165,0 @@ resolve(); |
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.2.0](https://github.com/shayeLee/imgsharp/compare/v1.1.3...v1.2.0) (2024-03-22) | ||
### Features | ||
* **option:** ✨ scale ([3688bc0](https://github.com/shayeLee/imgsharp/commit/3688bc068a8c4bca994e0e836b7eaa89472b5635)) | ||
### [1.1.3](https://github.com/shayeLee/imgsharp/compare/v1.1.2...v1.1.3) (2024-01-08) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "imagsharp", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"type": "module", | ||
@@ -14,4 +14,3 @@ "engines": { | ||
"build": "rm -rf ./bin && tsc", | ||
"debug": "rm -rf imagsharp-dest && tsx src/index.ts assets", | ||
"test": "rm -rf imagsharp-dest && bin/index.js" | ||
"debug": "rm -rf imagsharp-dest && tsx src/index.ts assets -s 0.69" | ||
}, | ||
@@ -18,0 +17,0 @@ "keywords": [], |
@@ -33,2 +33,4 @@ #!/usr/bin/env node | ||
program.option("-s, --scale [scale]", "The scale of the picture"); | ||
program.option("-f, --format [format]", "The media type of the picture"); | ||
@@ -43,2 +45,3 @@ | ||
_width: number, | ||
scale: number, | ||
quality: number, | ||
@@ -57,3 +60,3 @@ _format: string | ||
const metadata = await img.metadata(); | ||
const width = _width || metadata.width; | ||
const width = Math.round(((_width || metadata.width) as number) * scale); | ||
const name = pathObj.name; | ||
@@ -176,2 +179,10 @@ const format = _format || ext.slice(1); | ||
} | ||
let scale = 1; | ||
if (typeof opts.scale === "string" && opts.scale.length > 0) { | ||
const _scale = parseFloat(opts.scale); | ||
if (!isNaN(_scale)) { | ||
scale = _scale; | ||
} | ||
} | ||
@@ -188,3 +199,3 @@ let quality = 0; | ||
edit(imgPath, pathObj, dir, width, quality, opts.format).finally(() => { | ||
edit(imgPath, pathObj, dir, width, scale, quality, opts.format).finally(() => { | ||
progressBar.tick(); | ||
@@ -191,0 +202,0 @@ resolve(); |
Sorry, the diff of this file is not supported yet
24054
351