Compare commits
2
Commits
8670eb372f
...
c7877eff74
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7877eff74 | ||
|
|
03d268ac89 |
+3
-2
@@ -10,8 +10,9 @@ source "$SCRIPT_DIR/config.sh"
|
|||||||
|
|
||||||
echo "Resizing large JPGs in $(pwd)"
|
echo "Resizing large JPGs in $(pwd)"
|
||||||
|
|
||||||
find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -print0 | while IFS= read -r -d '' f
|
find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -printf '%s\t%p\0' | \
|
||||||
do
|
sort -z -t$'\t' -k1,1rn | \
|
||||||
|
while IFS=$'\t' read -r -d '' _size f; do
|
||||||
# Skip files already processed with these parameters
|
# Skip files already processed with these parameters
|
||||||
COMMENT=$(~/Applications/magick identify -format "%c" "$f" 2>/dev/null)
|
COMMENT=$(~/Applications/magick identify -format "%c" "$f" 2>/dev/null)
|
||||||
if [[ "$COMMENT" == "$MAGICK_COMMENT" ]]; then
|
if [[ "$COMMENT" == "$MAGICK_COMMENT" ]]; then
|
||||||
|
|||||||
@@ -53,6 +53,29 @@ teardown() {
|
|||||||
assert_equal "$(grep -c 'Resized' <<<"$output")" "2"
|
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" {
|
@test "no temp files left in /dev/shm after recursive run" {
|
||||||
make_zip "$TEST_WORKDIR/a.zip" "$FIXTURES/unprocessed.jpg"
|
make_zip "$TEST_WORKDIR/a.zip" "$FIXTURES/unprocessed.jpg"
|
||||||
make_zip "$TEST_WORKDIR/b.zip" "$FIXTURES/processed.jpg"
|
make_zip "$TEST_WORKDIR/b.zip" "$FIXTURES/processed.jpg"
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ fi
|
|||||||
|
|
||||||
echo "Resizing images in ZIPs recursively in $SEARCH_DIR"
|
echo "Resizing images in ZIPs recursively in $SEARCH_DIR"
|
||||||
|
|
||||||
find "$SEARCH_DIR" -iname '*.zip' -print0 | while IFS= read -r -d '' f
|
find "$SEARCH_DIR" -iname '*.zip' -printf '%s\t%p\0' | \
|
||||||
do
|
sort -z -t$'\t' -k1,1rn | \
|
||||||
"$SCRIPT_DIR/zip_images_resize.sh" "$f"
|
while IFS=$'\t' read -r -d '' _size f; do
|
||||||
done
|
"$SCRIPT_DIR/zip_images_resize.sh" "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user