imgstat 1.0.3 → 1.0.4
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 +46 -3
- package/package.json +1 -1
package/imagestat
CHANGED
|
@@ -26,11 +26,54 @@ if [ ! -d "$TARGET_DIR" ]; then
|
|
|
26
26
|
mkdir -p "$TARGET_DIR"
|
|
27
27
|
fi
|
|
28
28
|
|
|
29
|
+
# Download images if URL is provided
|
|
29
30
|
# Download images if URL is provided
|
|
30
31
|
if [ -n "$URL" ]; then
|
|
31
|
-
echo "Downloading images from $URL to
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
echo "Downloading images from $URL to temp folder..."
|
|
33
|
+
TEMP_DIR=$(mktemp -d)
|
|
34
|
+
|
|
35
|
+
# Download with wget (no extension restriction to catch all images)
|
|
36
|
+
# -nd: no directories (flatten)
|
|
37
|
+
# -r: recursive (useful if URL is a directory, but works for single file too)
|
|
38
|
+
# -l 1: limit recursion depth to 1 just in case (optional, but safer)
|
|
39
|
+
# --no-parent: don't go up
|
|
40
|
+
wget -nd -H -P "$TEMP_DIR" -e robots=off --user-agent="Mozilla/5.0" "$URL" 2>/dev/null
|
|
41
|
+
|
|
42
|
+
echo "Processing downloaded files..."
|
|
43
|
+
shopt -s nullglob
|
|
44
|
+
for f in "$TEMP_DIR"/*; do
|
|
45
|
+
if [ -f "$f" ]; then
|
|
46
|
+
# Identify format and dimensions (take first frame for animated gifs etc)
|
|
47
|
+
# Use -ping to be faster? identification doesn't need full read usually
|
|
48
|
+
ID_OUTPUT=$(identify -format "%m %w %h" "$f[0]" 2>/dev/null)
|
|
49
|
+
|
|
50
|
+
if [ -n "$ID_OUTPUT" ]; then
|
|
51
|
+
read -r TYPE W H <<< "$ID_OUTPUT"
|
|
52
|
+
|
|
53
|
+
# Normalize extension
|
|
54
|
+
EXT=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]')
|
|
55
|
+
case "$EXT" in
|
|
56
|
+
jpeg) EXT="jpg" ;;
|
|
57
|
+
esac
|
|
58
|
+
|
|
59
|
+
# Get clean basename (remove query params)
|
|
60
|
+
BASENAME=$(basename "$f")
|
|
61
|
+
CLEAN_NAME=$(echo "$BASENAME" | sed 's/[?=&].*//')
|
|
62
|
+
# Remove existing extension if it matches common ones
|
|
63
|
+
CLEAN_NAME="${CLEAN_NAME%.*}"
|
|
64
|
+
|
|
65
|
+
# Construct new filename
|
|
66
|
+
NEW_FILENAME="${CLEAN_NAME}-${W}x${H}.${EXT}"
|
|
67
|
+
NEW_PATH="$TARGET_DIR/$NEW_FILENAME"
|
|
68
|
+
|
|
69
|
+
# Move to target
|
|
70
|
+
mv -n "$f" "$NEW_PATH"
|
|
71
|
+
echo "Saved: $NEW_FILENAME ($W x $H)"
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
74
|
+
done
|
|
75
|
+
rm -rf "$TEMP_DIR"
|
|
76
|
+
echo "Download processing complete."
|
|
34
77
|
fi
|
|
35
78
|
|
|
36
79
|
# Export function so xargs can use it
|