heic-png-converter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Lucas Larangeira <lukearch@proton.me>.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const fs_extra_1 = require("fs-extra");
5
+ const picocolors_1 = require("picocolors");
6
+ const addHeicExtensionCommand = new commander_1.Command('add-heic-extension')
7
+ .description('Add .heic extension to all files in the current directory')
8
+ .action(async () => {
9
+ const root = process.cwd();
10
+ process.chdir(root);
11
+ console.log((0, picocolors_1.blue)('Adding .heic extension to all files in the current directory'));
12
+ const files = (0, fs_extra_1.readdirSync)(root).filter((file) => !file.includes('.'));
13
+ if (files.length === 0) {
14
+ console.log((0, picocolors_1.blue)('No files found in the current directory.'));
15
+ return;
16
+ }
17
+ for (const file of files) {
18
+ const newFile = `${file}.heic`;
19
+ await (0, fs_extra_1.rename)(file, newFile);
20
+ console.log(`Renaming ${file} to ${newFile}`);
21
+ }
22
+ console.log((0, picocolors_1.blue)('\nAdding .heic extension complete!'));
23
+ });
24
+ exports.default = addHeicExtensionCommand;
25
+ //# sourceMappingURL=add-heic-extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-heic-extension.js","sourceRoot":"","sources":["../../src/commands/add-heic-extension.ts"],"names":[],"mappings":";;AAAA,yCAAoC;AACpC,uCAA+C;AAC/C,2CAAkC;AAElC,MAAM,uBAAuB,GAAG,IAAI,mBAAO,CAAC,oBAAoB,CAAC;KAC9D,WAAW,CAAC,2DAA2D,CAAC;KACxE,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,CAAC,GAAG,CACT,IAAA,iBAAI,EAAC,8DAA8D,CAAC,CACrE,CAAC;IAEF,MAAM,KAAK,GAAG,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAEtE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,0CAA0C,CAAC,CAAC,CAAC;QAC9D,OAAO;IACT,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,GAAG,IAAI,OAAO,CAAC;QAC/B,MAAM,IAAA,iBAAM,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,OAAO,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,oCAAoC,CAAC,CAAC,CAAC;AAC1D,CAAC,CAAC,CAAC;AAEL,kBAAe,uBAAuB,CAAC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const fs_extra_1 = require("fs-extra");
5
+ const promises_1 = require("fs/promises");
6
+ const heicConvert = require("heic-convert");
7
+ const path_1 = require("path");
8
+ const picocolors_1 = require("picocolors");
9
+ const prompts = require("prompts");
10
+ const sharp = require("sharp");
11
+ const convertAllCommand = new commander_1.Command('convert-all')
12
+ .description('Convert all .heic files in the current directory to .png')
13
+ .action(async () => {
14
+ const answers = await prompts([
15
+ {
16
+ type: 'number',
17
+ name: 'quality',
18
+ message: 'Enter the quality of the converted images (0-100)',
19
+ initial: 100,
20
+ min: 0,
21
+ max: 100,
22
+ },
23
+ {
24
+ type: 'confirm',
25
+ name: 'delete',
26
+ message: 'Delete the original .heic files after conversion?',
27
+ initial: false,
28
+ },
29
+ {
30
+ type: 'confirm',
31
+ name: 'confirm',
32
+ message: 'Do you want to proceed?',
33
+ initial: true,
34
+ },
35
+ ]);
36
+ if (!answers.confirm) {
37
+ console.log((0, picocolors_1.blue)('\nAborted.'));
38
+ return;
39
+ }
40
+ const root = (0, path_1.resolve)(process.cwd());
41
+ process.chdir(root);
42
+ console.log((0, picocolors_1.blue)('Converting all .heic files to .png\n'));
43
+ const files = (0, fs_extra_1.readdirSync)(root).map((file) => file.toLowerCase()).filter((file) => file.endsWith('.heic'));
44
+ if (files.length === 0) {
45
+ console.log((0, picocolors_1.blue)('No .heic files found in the current directory.'));
46
+ return;
47
+ }
48
+ for (const file of files) {
49
+ console.log(`Converting ${file}...`);
50
+ const inputBuffer = await (0, fs_extra_1.readFile)((0, path_1.resolve)(root, file));
51
+ const outputBuffer = await heicConvert({
52
+ buffer: inputBuffer.buffer.slice(inputBuffer.byteOffset, inputBuffer.byteOffset + inputBuffer.byteLength),
53
+ format: 'PNG',
54
+ quality: 1,
55
+ });
56
+ const newPNGFile = file.replace('.heic', '.png');
57
+ await sharp(outputBuffer)
58
+ .png({ quality: 80 })
59
+ .toFile((0, path_1.resolve)(root, newPNGFile));
60
+ if (answers.delete) {
61
+ await (0, promises_1.unlink)((0, path_1.resolve)(root, file));
62
+ }
63
+ }
64
+ console.log((0, picocolors_1.blue)('\nConversion complete!'));
65
+ });
66
+ exports.default = convertAllCommand;
67
+ //# sourceMappingURL=convert-all.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-all.js","sourceRoot":"","sources":["../../src/commands/convert-all.ts"],"names":[],"mappings":";;AAAA,yCAAoC;AACpC,uCAAiD;AACjD,0CAAqC;AACrC,4CAA4C;AAC5C,+BAA+B;AAC/B,2CAAkC;AAClC,mCAAmC;AACnC,+BAAgC;AAEhC,MAAM,iBAAiB,GAAG,IAAI,mBAAO,CAAC,aAAa,CAAC;KACjD,WAAW,CAAC,0DAA0D,CAAC;KACvE,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC;QAC5B;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,mDAAmD;YAC5D,OAAO,EAAE,GAAG;YACZ,GAAG,EAAE,CAAC;YACN,GAAG,EAAE,GAAG;SACT;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,mDAAmD;YAC5D,OAAO,EAAE,KAAK;SACf;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,yBAAyB;YAClC,OAAO,EAAE,IAAI;SACd;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,YAAY,CAAC,CAAC,CA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B,MAAM,CAAC,IAAA,cAAO,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;QAErC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAA,iBAAM,EAAC,IAAA,cAAO,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,wBAAwB,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC;AAEL,kBAAe,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const convert_all_1 = require("./commands/convert-all");
6
+ const add_heic_extension_1 = require("./commands/add-heic-extension");
7
+ const run = async () => {
8
+ const pkgJson = await Promise.resolve().then(() => require('../package.json'));
9
+ const program = new commander_1.Command()
10
+ .version(pkgJson.version)
11
+ .description(pkgJson.description)
12
+ .addCommand(convert_all_1.default)
13
+ .addCommand(add_heic_extension_1.default);
14
+ program.parse(process.argv);
15
+ };
16
+ run();
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,wDAAuD;AACvD,sEAAoE;AAEpE,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;IACrB,MAAM,OAAO,GAAG,2CAAa,iBAAiB,EAAC,CAAC;IAEhD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE;SAC1B,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;SACxB,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC;SAChC,UAAU,CAAC,qBAAiB,CAAC;SAC7B,UAAU,CAAC,4BAAuB,CAAC,CAAC;IAEvC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,GAAG,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "heic-png-converter",
3
+ "version": "0.1.0",
4
+ "description": "Convert HEIC images to PNG",
5
+ "files": [
6
+ "dist",
7
+ "LICENSE",
8
+ "README.md",
9
+ "package.json"
10
+ ],
11
+ "bin": {
12
+ "heic2png": "./dist/index.js"
13
+ },
14
+ "author": {
15
+ "email": "luketsx@icloud.com",
16
+ "name": "Lucas Arch"
17
+ },
18
+ "license": "MIT",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/luketsx/heic-png-converter.git"
25
+ },
26
+ "devDependencies": {
27
+ "@types/commander": "^2.12.2",
28
+ "@types/fs-extra": "^11.0.4",
29
+ "@types/heic-convert": "^1.2.3",
30
+ "@types/node": "^20.11.30",
31
+ "@types/prompts": "^2.4.9",
32
+ "@types/sharp": "^0.32.0",
33
+ "@typescript-eslint/eslint-plugin": "^7.4.0",
34
+ "@typescript-eslint/parser": "^7.4.0",
35
+ "eslint-config-prettier": "^9.1.0",
36
+ "prettier": "^3.2.5",
37
+ "ts-node": "^10.9.2",
38
+ "typescript": "^5.4.3"
39
+ },
40
+ "dependencies": {
41
+ "commander": "^12.0.0",
42
+ "fs-extra": "^11.2.0",
43
+ "heic-convert": "^2.1.0",
44
+ "picocolors": "^1.0.0",
45
+ "prompts": "^2.4.2",
46
+ "sharp": "^0.33.3"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc",
50
+ "lint": "eslint . --ext .ts",
51
+ "start": "ts-node src/index.ts",
52
+ "format": "prettier --write ."
53
+ }
54
+ }