Last active
July 24, 2024 10:47
-
-
Save bokwoon95/ee940d1fb80d3605aa407a9869348005 to your computer and use it in GitHub Desktop.
Revisions
-
bokwoon95 revised this gist
Jul 24, 2024 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ exit 1 fi width="$(vipsheader "$INPUT_PATH" -f width)" height="$(vipsheader "$INPUT_PATH" -f height)" scale_factor="$(awk -v "width=$width" -v "height=$height" "BEGIN { aspect_ratio = width / height; is_tall_img = aspect_ratio < 9 / 16; if (is_tall_img || width > height) { @@ -26,11 +26,11 @@ scale_factor="$(awk -v "width=$width" -v "height=$height" 'BEGIN { print 1080 / height; } } }")" if test "$scale_factor" = "1"; then mv "$INPUT_PATH" "$OUTPUT_PATH" else vips resize "$INPUT_PATH" "$OUTPUT_PATH" "$scale_factor" echo "$INPUT_PATH: input_width = $width, input_height = $height" echo "$OUTPUT_PATH: output_width = $(vipsheader "$OUTPUT_PATH" -f width), output_height = $(vipsheader "$OUTPUT_PATH" -f height)" fi -
bokwoon95 renamed this gist
Jul 1, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bokwoon95 created this gist
Jul 1, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/usr/bin/env bash set -e set -u set -o pipefail INPUT_PATH="$1" OUTPUT_PATH="$2" if test ! -f "$INPUT_PATH"; then echo "INPUT_PATH $INPUT_PATH does not exist" exit 1 fi width="$(vipsheader "$INPUT_PATH" -f width)" height="$(vipsheader "$INPUT_PATH" -f height)" scale_factor="$(awk -v "width=$width" -v "height=$height" 'BEGIN { aspect_ratio = width / height; is_tall_img = aspect_ratio < 9 / 16; if (is_tall_img || width > height) { if (width <= 1080) { print 1; } else { print 1080 / width; } } else { if (height <= 1080) { print 1; } else { print 1080 / height; } } }')" if test "$scale_factor" = "1"; then mv "$INPUT_PATH" "$OUTPUT_PATH" else vips resize "$INPUT_PATH" "$OUTPUT_PATH" "$scale_factor" echo "$INPUT_PATH: width = $width, old height = $height" echo "$OUTPUT_PATH: width = $(vipsheader "$OUTPUT_PATH" -f width), height = $(vipsheader "$OUTPUT_PATH" -f height)" fi