Compare commits

...
2 Commits
Author SHA1 Message Date
poprhythm c7877eff74 Sort JPEGs by size descending before resizing 2026-07-04 22:45:33 -04:00
poprhythm 03d268ac89 Sort ZIPs by size descending before processing 2026-07-04 22:45:06 -04:00
3 changed files with 31 additions and 6 deletions
+3 -2
View File
@@ -10,8 +10,9 @@ source "$SCRIPT_DIR/config.sh"
echo "Resizing large JPGs in $(pwd)"
find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -print0 | while IFS= read -r -d '' f
do
find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -printf '%s\t%p\0' | \
sort -z -t$'\t' -k1,1rn | \
while IFS=$'\t' read -r -d '' _size f; do
# Skip files already processed with these parameters
COMMENT=$(~/Applications/magick identify -format "%c" "$f" 2>/dev/null)
if [[ "$COMMENT" == "$MAGICK_COMMENT" ]]; then
+23
View File
@@ -53,6 +53,29 @@ teardown() {
assert_equal "$(grep -c 'Resized' <<<"$output")" "2"
}
@test "processes ZIPs in descending size order" {
# Create ZIPs of different sizes by varying image dimensions
local small medium large
small="$TEST_WORKDIR/small.zip"
medium="$TEST_WORKDIR/medium.zip"
large="$TEST_WORKDIR/large.zip"
convert -size 50x50 xc:gray "$TEST_WORKDIR/s.jpg"
convert -size 100x100 xc:gray "$TEST_WORKDIR/m.jpg"
convert -size 200x200 xc:gray "$TEST_WORKDIR/l.jpg"
(cd "$TEST_WORKDIR" && zip -q small.zip s.jpg)
(cd "$TEST_WORKDIR" && zip -q medium.zip m.jpg)
(cd "$TEST_WORKDIR" && zip -q large.zip l.jpg)
run "$SCRIPT" "$TEST_WORKDIR"
assert_success
# Extract the order ZIPs were processed from the output
local order
order=$(grep 'Processing file' <<<"$output" | grep -o '[a-z]*.zip' | tr '\n' ' ')
assert_equal "$order" "large.zip medium.zip small.zip "
}
@test "no temp files left in /dev/shm after recursive run" {
make_zip "$TEST_WORKDIR/a.zip" "$FIXTURES/unprocessed.jpg"
make_zip "$TEST_WORKDIR/b.zip" "$FIXTURES/processed.jpg"
+3 -2
View File
@@ -10,8 +10,9 @@ fi
echo "Resizing images in ZIPs recursively in $SEARCH_DIR"
find "$SEARCH_DIR" -iname '*.zip' -print0 | while IFS= read -r -d '' f
do
find "$SEARCH_DIR" -iname '*.zip' -printf '%s\t%p\0' | \
sort -z -t$'\t' -k1,1rn | \
while IFS=$'\t' read -r -d '' _size f; do
"$SCRIPT_DIR/zip_images_resize.sh" "$f"
done