Skip to content

Commit

Permalink
fix windows file system issue
Browse files Browse the repository at this point in the history
  • Loading branch information
devmuaz committed Nov 25, 2021
1 parent 45e34e9 commit 7cec274
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.0.3 (2021-11-25)

- fix windows file system issue

## v0.0.2 (2021-11-24)

- update README.md file
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "flutter-image-assets",
"displayName": "Flutter Image Assets",
"description": "A simple VS Code extension which helps you generate your image assets in 1x, 2x, and 3x and simply added them to your pubspec.yaml file.",
"version": "0.0.2",
"version": "0.0.3",
"publisher": "devmuaz",
"icon": "assets/icon.png",
"repository": {
Expand Down
27 changes: 14 additions & 13 deletions src/image_utils.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
const fs = require('fs');
const path = require('path');
const Jimp = require('jimp');

/**
*
* @param {string} destImagePath
* @param {string} directoryPath
* @param {string} imagePath
* @param {number} mode
* @param {number} scale
* @returns
*/
const scaleImageToMode = (destImagePath, imagePath, mode, scale = 0.25) => {
const fileName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.length);
var path = `${destImagePath}/${fileName}`;
const scaleImageToMode = (directoryPath, imagePath, mode, scale = 0.25) => {
const fileName = path.basename(imagePath);
var destinationPath = path.join(directoryPath, fileName);
if (mode == 1) {
scaleImage(path, imagePath, scale);
scaleImage(destinationPath, imagePath, scale);
return;
}

path = `/${destImagePath}/${mode}x/`;
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
destinationPath = path.join(directoryPath, `${mode}x`);
if (!fs.existsSync(destinationPath)) {
fs.mkdirSync(destinationPath);
}
scaleImage(`${path}${fileName}`, imagePath, mode == 2 ? 0.50 : mode == 3 ? 0.75 : scale);

scaleImage(path.join(destinationPath, fileName), imagePath, mode == 2 ? 0.50 : mode == 3 ? 0.75 : scale);
};

/**
*
* @param {string} destImagePath
* @param {string} destinationImagePath
* @param {string} imagePath
* @param {number} scale
* @returns
*/
const scaleImage = (destImagePath, imagePath, scale) => {
const scaleImage = (destinationImagePath, imagePath, scale) => {
return new Promise((resolve, reject) => {
Jimp.read(imagePath, (error, image) => {
if (error) {
reject(error);
console.log(error);
throw error;
}
image.scale(scale).write(destImagePath);
image.scale(scale).write(destinationImagePath);
resolve();
});
});
Expand Down

0 comments on commit 7cec274

Please sign in to comment.