Skip to content

Commit

Permalink
Fix file with extension
Browse files Browse the repository at this point in the history
  • Loading branch information
thinknathan committed Dec 19, 2023
1 parent b28715c commit 9423c42
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-simple-pixelate",
"version": "1.1.0",
"version": "1.1.1",
"description": "Pixelizes images to create pixel art.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions px.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ const options = yargs
return Math.round(value);
},
}).argv;
if (options.filename !== undefined) {
if (options.filename) {
// Process a single image
(0, processImage_1.processImage)(options);
} else if (options.folderPath !== undefined) {
} else if (options.folderPath) {
// Process all images in a folder, splitting the task into threads
let numCores = 2;
try {
Expand Down
4 changes: 2 additions & 2 deletions src/px.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ const options = yargs
},
}).argv as unknown as Options;

if (options.filename !== undefined) {
if (options.filename) {
// Process a single image
processImage(options);
} else if (options.folderPath !== undefined) {
} else if (options.folderPath) {
// Process all images in a folder, splitting the task into threads
let numCores = 2;
try {
Expand Down
48 changes: 28 additions & 20 deletions src/utils/processImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,42 @@ export function processImage(options: Options, skipExtCheck?: boolean): void {
height,
} = options;

if (filename && skipExtCheck) {
if (filename) {
Jimp.read(filename, (err, image) => {
if (err) {
if (err && skipExtCheck) {
console.error(err);
} else {
continueProcessing(
image,
scale,
pixelSize,
ditherAlgo,
alphaThreshold,
colorLimit,
palette,
customPalette,
randomColor,
lowPass,
normalize,
grayScale,
contrast,
width,
height,
filename,
);
// Continue if image is successfully read
if (image) {
continueProcessing(
image,
scale,
pixelSize,
ditherAlgo,
alphaThreshold,
colorLimit,
palette,
customPalette,
randomColor,
lowPass,
normalize,
grayScale,
contrast,
width,
height,
filename,
);
return;
}
}
});
}

if (skipExtCheck) {
return;
}

// Check for supported image formats if skipExtCheck is false
const supportedFormats = [".png", ".gif", ".jpg", ".jpeg"];
let foundImage = false;

Expand Down
13 changes: 10 additions & 3 deletions utils/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@ const definedPalettes = definedPalettes_1.definedPalettesImport;
*/
function processImage(options, skipExtCheck) {
const { filename, scale, pixelSize, ditherAlgo, alphaThreshold, colorLimit, palette, customPalette, randomColor, lowPass, normalize, grayScale, contrast, width, height, } = options;
if (filename && skipExtCheck) {
if (filename) {
Jimp.read(filename, (err, image) => {
if (err) {
if (err && skipExtCheck) {
console.error(err);
}
else {
continueProcessing(image, scale, pixelSize, ditherAlgo, alphaThreshold, colorLimit, palette, customPalette, randomColor, lowPass, normalize, grayScale, contrast, width, height, filename);
// Continue if image is successfully read
if (image) {
continueProcessing(image, scale, pixelSize, ditherAlgo, alphaThreshold, colorLimit, palette, customPalette, randomColor, lowPass, normalize, grayScale, contrast, width, height, filename);
return;
}
}
});
}
if (skipExtCheck) {
return;
}
// Check for supported image formats if skipExtCheck is false
const supportedFormats = [".png", ".gif", ".jpg", ".jpeg"];
let foundImage = false;
// Attempt to read the image with different extensions
Expand Down

0 comments on commit 9423c42

Please sign in to comment.