This repository was archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiple files wildcard need an destination directory given as 3rd argument.
- Loading branch information
1 parent
fbd592c
commit ef11bae
Showing
1 changed file
with
31 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,46 @@ | ||
#!/bin/sh | ||
if [[ $# -eq 0 ]] ; then | ||
echo 'Filename needed' | ||
echo 'File needed' | ||
exit 1 | ||
fi | ||
|
||
filename="$1" | ||
basename=${filename%.*} | ||
type="${filename##*.}" | ||
input="$1" | ||
pathfile=${input%.*} | ||
type="${input##*.}" | ||
|
||
quality=80 | ||
if ! [[ -z "$2" ]] ; then | ||
quality=$2 | ||
fi | ||
|
||
final="$pathfile" | ||
if ! [[ -z "$3" ]] ; then | ||
# filename with no path | ||
filename="${input##*/}" | ||
final="$3/${filename%.*}" | ||
fi | ||
|
||
# change convert options as needed | ||
options="-strip -interlace Plane -quality $quality" | ||
|
||
echo "Resizing $filename to 320,480,640,768,960,1024,1280,1440 sizes using $quality quality" | ||
echo "Resizing $input to 320,480,640,768,960,1024,1280,1440 sizes using $quality quality" | ||
|
||
# Various resizes | ||
convert $options -adaptive-resize 320 "$filename" "$basename-320w.$type" | ||
convert $options -adaptive-resize 480 "$filename" "$basename-480w.$type" | ||
convert $options -adaptive-resize 640 "$filename" "$basename-640w.$type" | ||
convert $options -adaptive-resize 768 "$filename" "$basename-768w.$type" | ||
convert $options -adaptive-resize 960 "$filename" "$basename-960w.$type" | ||
convert $options -adaptive-resize 1024 "$filename" "$basename-1024w.$type" | ||
convert $options -adaptive-resize 1280 "$filename" "$basename-1280w.$type" | ||
convert $options -adaptive-resize 1440 "$filename" "$basename-1440w.$type" | ||
echo "" | ||
|
||
echo '<img src="'$basename-768w.$type'" srcset="'$basename-320w.$type' 320w, '$basename-480w.$type' 480w, '$basename-640w.$type' 640w, '$basename-768w.$type' 768w, '$basename-960w.$type' 960w, '$basename-1024w.$type' 1024w, '$basename-1440w.$type' 1440w", sizes="(min-width: 768px) 50vw, 100vw" alt="An image named '$filename'"/>' | ||
convert $options -adaptive-resize 320 "$input" "$final-320w.$type" | ||
|
||
convert $options -adaptive-resize 480 "$input" "$final-480w.$type" | ||
convert $options -adaptive-resize 640 "$input" "$final-640w.$type" | ||
convert $options -adaptive-resize 768 "$input" "$final-768w.$type" | ||
convert $options -adaptive-resize 960 "$input" "$final-960w.$type" | ||
convert $options -adaptive-resize 1024 "$input" "$final-1024w.$type" | ||
convert $options -adaptive-resize 1280 "$input" "$final-1280w.$type" | ||
convert $options -adaptive-resize 1440 "$input" "$final-1440w.$type" | ||
|
||
str='<img src="'$final-480w.$type'" srcset="'$final-320w.$type' 320w, '$final-480w.$type' 480w, '$final-640w.$type' 640w, '$final-768w.$type' 768w, '$final-960w.$type' 960w, '$final-1024w.$type' 1024w, '$final-1440w.$type' 1440w", sizes="(min-width: 768px) 50vw, 100vw" alt="An image named '$input'"/>' | ||
|
||
if ! [[ -z "$3" ]] ; then | ||
echo "$str" > "$final-srcset.html" | ||
echo "more $final-srcset.html" | ||
else | ||
echo "$str" | ||
fi |