imgstat 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/imagestat +81 -0
- package/package.json +29 -0
- package/readme.md +55 -0
package/imagestat
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Function to display usage
|
|
4
|
+
usage() {
|
|
5
|
+
echo "Usage: imagestat [-u|--url <url>] [directory]"
|
|
6
|
+
echo " -u, --url <url> URL to download images from"
|
|
7
|
+
echo " directory Directory to scan (default: current directory)"
|
|
8
|
+
exit 1
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
# Parse arguments
|
|
12
|
+
URL=""
|
|
13
|
+
TARGET_DIR="."
|
|
14
|
+
|
|
15
|
+
while [[ "$#" -gt 0 ]]; do
|
|
16
|
+
case $1 in
|
|
17
|
+
-u|--url) URL="$2"; shift ;;
|
|
18
|
+
-*) echo "Unknown parameter passed: $1"; usage ;;
|
|
19
|
+
*) TARGET_DIR="$1" ;;
|
|
20
|
+
esac
|
|
21
|
+
shift
|
|
22
|
+
done
|
|
23
|
+
|
|
24
|
+
# Create target directory if it doesn't exist
|
|
25
|
+
if [ ! -d "$TARGET_DIR" ]; then
|
|
26
|
+
mkdir -p "$TARGET_DIR"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Download images if URL is provided
|
|
30
|
+
if [ -n "$URL" ]; then
|
|
31
|
+
echo "Downloading images from $URL to $TARGET_DIR..."
|
|
32
|
+
wget -nd -r -P "$TARGET_DIR" -A jpeg,jpg,bmp,gif,png,webp,svg "$URL" 2>/dev/null
|
|
33
|
+
echo "Download complete."
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Export function so xargs can use it
|
|
37
|
+
process_image() {
|
|
38
|
+
IMG="$1"
|
|
39
|
+
|
|
40
|
+
# Get dimensions
|
|
41
|
+
DIMENSIONS=$(identify -format "%wx%h" "$IMG" 2>/dev/null)
|
|
42
|
+
|
|
43
|
+
if [ -z "$DIMENSIONS" ]; then
|
|
44
|
+
echo "Skipping (not an image or identify failed): $IMG"
|
|
45
|
+
return
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
DIRNAME=$(dirname "$IMG")
|
|
49
|
+
BASENAME=$(basename "$IMG")
|
|
50
|
+
EXTENSION="${BASENAME##*.}"
|
|
51
|
+
FILENAME="${BASENAME%.*}"
|
|
52
|
+
|
|
53
|
+
# Normalize filename: lowercase, replace spaces/underscores with hyphens
|
|
54
|
+
NEW_FILENAME=$(echo "$FILENAME" | tr '[:upper:]' '[:lower:]' | sed 's/[ _]/-/g' | sed 's/-\{2,\}/-/g')
|
|
55
|
+
|
|
56
|
+
# Check if dimensions are already in the filename
|
|
57
|
+
if [[ "$NEW_FILENAME" != *"$DIMENSIONS"* ]]; then
|
|
58
|
+
NEW_FILENAME="${NEW_FILENAME}-${DIMENSIONS}"
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
NEW_BASENAME="${NEW_FILENAME}.${EXTENSION}"
|
|
62
|
+
NEW_PATH="$DIRNAME/$NEW_BASENAME"
|
|
63
|
+
|
|
64
|
+
if [ "$IMG" != "$NEW_PATH" ]; then
|
|
65
|
+
mv "$IMG" "$NEW_PATH"
|
|
66
|
+
echo "Renamed: $IMG -> $NEW_PATH"
|
|
67
|
+
else
|
|
68
|
+
echo "No change: $IMG"
|
|
69
|
+
fi
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export -f process_image
|
|
73
|
+
|
|
74
|
+
# Find and process images
|
|
75
|
+
echo "Scanning for images in $TARGET_DIR..."
|
|
76
|
+
# Prune standard ignored directories
|
|
77
|
+
find "$TARGET_DIR" \
|
|
78
|
+
\( -type d -name ".git" -o -name "node_modules" -o -name "dist" -o -name "build" -o -name "vendor" -o -name ".next" -o -name "coverage" \) -prune \
|
|
79
|
+
-o -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.webp" -o -iname "*.svg" \) -print0 | xargs -0 -P 4 -I {} bash -c 'process_image "$@"' _ {}
|
|
80
|
+
|
|
81
|
+
echo "Done."
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "imgstat",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Recursive image dimensions scanner and renamer",
|
|
5
|
+
"bin": {
|
|
6
|
+
"imagestat": "./imagestat"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/isaac0yen/imgstat.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"image",
|
|
14
|
+
"resize",
|
|
15
|
+
"rename",
|
|
16
|
+
"dimensions",
|
|
17
|
+
"cli",
|
|
18
|
+
"bash"
|
|
19
|
+
],
|
|
20
|
+
"author": "Isaac",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/isaac0yen/imgstat/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/isaac0yen/imgstat#readme",
|
|
26
|
+
"files": [
|
|
27
|
+
"imagestat"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# imagestat
|
|
2
|
+
|
|
3
|
+
**imagestat** is a powerful bash utility that recursively scans directories for images, downloads them, and automatically renames them to include their dimensions (e.g., `image-1920x1080.jpg`).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Recursive Scanning**: Finds images deep within subdirectories.
|
|
8
|
+
- **Smart Renaming**: `My Photo.jpg` -> `my-photo-800x600.jpg`
|
|
9
|
+
- **Smart Ignores**: Skips `node_modules`, `.git`, `dist`, etc.
|
|
10
|
+
- **URL Download**: Optionally download images first.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### Option 1: NPM (Node.js)
|
|
15
|
+
The easiest way if you have Node.js installed:
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g imgstat
|
|
18
|
+
```
|
|
19
|
+
*Note: Requires a bash environment (Linux, macOS, WSL, or Git Bash).*
|
|
20
|
+
|
|
21
|
+
### Option 2: Universal Install Script (Linux/macOS)
|
|
22
|
+
One-line install from your terminal:
|
|
23
|
+
```bash
|
|
24
|
+
curl -fsSL https://raw.githubusercontent.com/isaac0yen/imgstat/main/install.sh | sudo bash
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Option 3: Debian/Ubuntu (.deb)
|
|
28
|
+
If you prefer a package manager:
|
|
29
|
+
1. Download the latest `.deb` from the [Releases page](https://github.com/isaac0yen/imgstat/releases).
|
|
30
|
+
2. Install it:
|
|
31
|
+
```bash
|
|
32
|
+
sudo apt install ./imagestat_1.0_all.deb
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Option 4: Manual
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/isaac0yen/imgstat.git
|
|
38
|
+
cd imgstat
|
|
39
|
+
sudo ./install.sh
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Windows
|
|
43
|
+
1. **Recommended**: Use **WSL** (Ubuntu) and follow "Option 2".
|
|
44
|
+
2. **Git Bash**: Clone the repo and run `./imagestat` directly.
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
imagestat [directory]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Download and process:**
|
|
53
|
+
```bash
|
|
54
|
+
imagestat -u https://example.com/images my-folder
|
|
55
|
+
```
|