@akurasiudara/img2webp 1.0.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Irfansyah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # img2webp
2
+
3
+ Simple command-line tool to convert images (JPG, JPEG, PNG) to WebP format.
4
+
5
+ ## Installation
6
+
7
+ ### Via npm (Global)
8
+ ```bash
9
+ npm install -g @akurasiudara/img2webp
10
+ ```
11
+
12
+ ### Prerequisites
13
+ - **cwebp** must be installed on your system
14
+ - **bash** (available on Linux/macOS, on Windows use WSL or Git Bash)
15
+
16
+ #### Install cwebp:
17
+
18
+ **Ubuntu/Debian:**
19
+ ```bash
20
+ sudo apt update
21
+ sudo apt install webp
22
+ ```
23
+
24
+ **macOS (Homebrew):**
25
+ ```bash
26
+ brew install webp
27
+ ```
28
+
29
+ **Windows:**
30
+ - Download from [Google WebP](https://developers.google.com/speed/webp/download)
31
+ - Or use [Chocolatey](https://chocolatey.org/): `choco install webp`
32
+
33
+ ## Usage
34
+
35
+ ### Basic Commands
36
+ ```bash
37
+ # Show help
38
+ img2webp --help
39
+
40
+ # Show version
41
+ img2webp --version
42
+ ```
43
+
44
+ ### Convert single file
45
+ ```bash
46
+ img2webp image.jpg 85
47
+ ```
48
+ - `image.jpg` = input file
49
+ - `85` = quality (optional, default: 80)
50
+
51
+ ### Batch convert all images in folder
52
+ ```bash
53
+ img2webp
54
+ ```
55
+ Will convert all JPG, JPEG, and PNG files in current directory.
56
+
57
+ ## Output
58
+
59
+ Converted files will be saved in `output/` folder with names:
60
+ - Single file: `image_001.webp`
61
+ - Batch: `image_001.webp`, `image_002.webp`, etc.
62
+
63
+ ## Examples
64
+
65
+ ```bash
66
+ # Convert single file with quality 90
67
+ img2webp photo.jpg 90
68
+
69
+ # Batch convert with default quality (80)
70
+ img2webp
71
+
72
+ # Convert single file with default quality
73
+ img2webp image.png
74
+
75
+ # Show help and options
76
+ img2webp --help
77
+ ```
78
+
79
+ ## Options
80
+
81
+ - `-h, --help` - Show help message
82
+ - `-v, --version` - Show version information
83
+
84
+ ## License
85
+
86
+ MIT
package/bin/img2webp ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ // Path ke script bash
8
+ const scriptPath = path.join(__dirname, '..', 'webp.sh');
9
+
10
+ // Cek apakah script ada
11
+ if (!fs.existsSync(scriptPath)) {
12
+ console.error('Error: webp.sh script not found!');
13
+ process.exit(1);
14
+ }
15
+
16
+ // Ambil arguments dari command line
17
+ const args = process.argv.slice(2);
18
+
19
+ // Jalankan script bash dengan arguments
20
+ const child = spawn('bash', [scriptPath, ...args], {
21
+ stdio: 'inherit',
22
+ cwd: process.cwd()
23
+ });
24
+
25
+ child.on('close', (code) => {
26
+ process.exit(code);
27
+ });
28
+
29
+ child.on('error', (err) => {
30
+ if (err.code === 'ENOENT') {
31
+ console.error('Error: Bash not found. This tool requires bash to be installed.');
32
+ } else {
33
+ console.error('Error:', err.message);
34
+ }
35
+ process.exit(1);
36
+ });
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@akurasiudara/img2webp",
3
+ "version": "1.0.0",
4
+ "description": "Simple command-line tool to convert images to WebP format",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "img2webp": "bin/img2webp"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": ["webp", "image", "converter", "cli", "img2webp"],
13
+ "author": "Ifan Irfansyah",
14
+ "license": "MIT",
15
+ "engines": {
16
+ "node": ">=12.0.0"
17
+ },
18
+ "files": [
19
+ "bin/",
20
+ "webp.sh",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "dependencies": {},
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/akurasiudara/img2webp.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/akurasiudara/img2webp/issues"
31
+ },
32
+ "homepage": "https://github.com/akurasiudara/img2webp#readme"
33
+ }
package/webp.sh ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Version and help
4
+ VERSION="1.0.0"
5
+ SCRIPT_NAME="img2webp"
6
+
7
+ show_help() {
8
+ cat << EOF
9
+ $SCRIPT_NAME v$VERSION - Simple WebP Image Converter
10
+
11
+ USAGE:
12
+ $SCRIPT_NAME [OPTIONS] [INPUT_FILE] [QUALITY]
13
+
14
+ DESCRIPTION:
15
+ Convert JPG, JPEG, and PNG images to WebP format.
16
+
17
+ Single file mode: Converts one specific image file
18
+ Batch mode: Converts all images in current directory
19
+
20
+ OPTIONS:
21
+ -h, --help Show this help message
22
+ -v, --version Show version information
23
+
24
+ ARGUMENTS:
25
+ INPUT_FILE Path to image file (optional for batch mode)
26
+ QUALITY WebP quality 0-100 (default: 80)
27
+
28
+ EXAMPLES:
29
+ # Convert single file with default quality (80)
30
+ $SCRIPT_NAME photo.jpg
31
+
32
+ # Convert single file with custom quality
33
+ $SCRIPT_NAME photo.jpg 90
34
+
35
+ # Batch convert all images in current directory
36
+ $SCRIPT_NAME
37
+
38
+ # Show help
39
+ $SCRIPT_NAME --help
40
+
41
+ OUTPUT:
42
+ Files will be saved to 'output/' directory as:
43
+ - Single: image_001.webp
44
+ - Batch: image_001.webp, image_002.webp, etc.
45
+
46
+ REQUIREMENTS:
47
+ - cwebp must be installed
48
+ - Ubuntu/Debian: sudo apt install webp
49
+ - macOS: brew install webp
50
+ - Windows: choco install webp
51
+
52
+ EOF
53
+ }
54
+
55
+ show_version() {
56
+ echo "$SCRIPT_NAME version $VERSION"
57
+ }
58
+
59
+ # Handle options
60
+ case "$1" in
61
+ -h|--help)
62
+ show_help
63
+ exit 0
64
+ ;;
65
+ -v|--version)
66
+ show_version
67
+ exit 0
68
+ ;;
69
+ esac
70
+
71
+ # Default quality
72
+ QUALITY=${2:-80}
73
+ INPUT_FILE="$1"
74
+
75
+ # Check if cwebp is installed
76
+ if ! command -v cwebp >/dev/null 2>&1; then
77
+ echo "Error: cwebp is not installed!"
78
+ echo "Please install webp tools:"
79
+ echo " Ubuntu/Debian: sudo apt install webp"
80
+ echo " macOS: brew install webp"
81
+ echo " Windows: choco install webp"
82
+ exit 1
83
+ fi
84
+
85
+ # Create output folder
86
+ mkdir -p output
87
+
88
+ # Convert function
89
+ convert_file() {
90
+ local img="$1"
91
+ local output="$2"
92
+
93
+ if [[ ! -f "$img" ]]; then
94
+ echo "File not found: $img"
95
+ return
96
+ fi
97
+
98
+ if cwebp -q "$QUALITY" "$img" -o "$output" >/dev/null 2>&1; then
99
+ echo "Converted: $img -> $output (quality=$QUALITY)"
100
+ else
101
+ echo "Failed to convert: $img"
102
+ fi
103
+ }
104
+
105
+ # Single file mode
106
+ if [[ -n "$INPUT_FILE" && -f "$INPUT_FILE" ]]; then
107
+ convert_file "$INPUT_FILE" "output/image_001.webp"
108
+ exit 0
109
+ fi
110
+
111
+ # Batch mode (alphabetical order, space-safe)
112
+ count=1
113
+ while IFS= read -r -d '' img; do
114
+ filename=$(printf "output/image_%03d.webp" "$count")
115
+ convert_file "$img" "$filename"
116
+ count=$((count + 1))
117
+ done < <(find . -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) -print0 | sort -z)
118
+
119
+ echo "Conversion completed!"