Skip to content

Commit f5942fd

Browse files
committed
WIP - Update bin/compress
1 parent 229df30 commit f5942fd

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

bin/compress

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ readonly REGEXP="^(.*)_(resize|crop)_(ldpi|mdpi|hdpi|xhdpi|xxhdpi|xxxhdpi)_(320|
4242
readonly SCRIPT_NAME=`basename "$0"`;
4343
readonly VERSION="1.0.0";
4444

45+
if [[ -x "$(command -v convert)" ]]; then
46+
CONVERT="convert"
47+
else
48+
CONVERT="${DIR}/convert-im6.q16"
49+
fi
50+
4551
########################################
4652
## Signal handler for SIGINT
4753
## Returns:
@@ -105,19 +111,15 @@ function generate() {
105111
local width=$7
106112
local height=$8
107113

114+
mkdir -p ${IMAGE_DIR}/${name}
108115
for target_width in ${FORMATS_WIDTH[*]}
109116
do
110117
for target_dpi_name in "${!DPI[@]}"
111118
do
112-
filename="${name}_${resize,,}_${target_dpi_name,,}_${target_width}"
119+
filename="${name}/${target_dpi_name,,}_${target_width}"
113120
echo '------';
114121
info "File to generate: ${filename}"
115122

116-
if [[ -f "${IMAGE_DIR}/${filename}" ]]; then
117-
info " already done";
118-
continue;
119-
fi
120-
121123
if [[ "$resize" == "RESIZE" ]]; then
122124
info " Go to resize";
123125
elif [[ "$resize" == "CROP" ]]; then
@@ -136,17 +138,32 @@ function generate() {
136138
if [[ $new_width_dpi -gt $width ]]; then
137139
warn "Warning: new width superior to original width ($new_width_dpi VS $width)";
138140
crop_from=$(ceil $(echo "scale=2; ($new_real_width_dpi_ratio - $new_width_dpi)/2" | bc))
139-
echo "CROP FROM = $crop_from";
140-
$DIR/cwebp -q 80 -o $IMAGE_DIR/tmp.webp -resize $new_real_width_dpi_ratio 0 -- $file
141-
$DIR/cwebp -q 80 -o $IMAGE_DIR/$filename.webp -crop $crop_from 0 $new_width_dpi $new_real_height_dpi_ratio -- $IMAGE_DIR/tmp.webp
142-
rm $IMAGE_DIR/tmp.webp
143-
convert $file -resize ${new_real_width_dpi_ratio}x${new_real_height_dpi_ratio} $IMAGE_DIR/tmp.jpg
144-
convert $IMAGE_DIR/tmp.jpg -crop ${new_width_dpi}x${new_real_height_dpi_ratio}+${crop_from}+0 -quality 60 $IMAGE_DIR/$filename.jpg
145-
rm $IMAGE_DIR/tmp.jpg
141+
if [[ -f "${IMAGE_DIR}/${filename}.webp" ]]; then
142+
info " WebP already done";
143+
else
144+
$DIR/cwebp -q 80 -o $IMAGE_DIR/tmp.webp -resize $new_real_width_dpi_ratio 0 -- $file
145+
$DIR/cwebp -q 80 -o $IMAGE_DIR/$filename.webp -crop $crop_from 0 $new_width_dpi $new_real_height_dpi_ratio -- $IMAGE_DIR/tmp.webp
146+
rm $IMAGE_DIR/tmp.webp
147+
fi
148+
if [[ -f "${IMAGE_DIR}/${filename}.jpg" ]]; then
149+
info " JPG already done";
150+
else
151+
$CONVERT $file -resize ${new_real_width_dpi_ratio}x${new_real_height_dpi_ratio} $IMAGE_DIR/tmp.jpg
152+
$CONVERT $IMAGE_DIR/tmp.jpg -crop ${new_width_dpi}x${new_real_height_dpi_ratio}+${crop_from}+0 -quality 60 $IMAGE_DIR/$filename.jpg
153+
rm $IMAGE_DIR/tmp.jpg
154+
fi
146155
else
147156
crop_from=$(ceil $(echo "scale=2; ($width - $new_width_dpi)/2" | bc))
148-
$DIR/cwebp -q 80 -o $IMAGE_DIR/$filename.webp -crop $crop_from 0 $new_width_dpi $height -- $file
149-
convert $file -crop ${new_width_dpi}x${height}+${crop_from}+0 -quality 60 $IMAGE_DIR/$filename.jpg
157+
if [[ -f "${IMAGE_DIR}/${filename}.webp" ]]; then
158+
info " WebP already done";
159+
else
160+
$DIR/cwebp -q 80 -o $IMAGE_DIR/$filename.webp -crop $crop_from 0 $new_width_dpi $height -- $file
161+
fi
162+
if [[ -f "${IMAGE_DIR}/${filename}.jpg" ]]; then
163+
info " JPG already done";
164+
else
165+
$CONVERT $file -crop ${new_width_dpi}x${height}+${crop_from}+0 -quality 60 $IMAGE_DIR/$filename.jpg
166+
fi
150167
fi
151168
else
152169
warn " Unknown resize '${resize}'";

bin/convert-im6.q16

5.99 KB
Binary file not shown.

0 commit comments

Comments
 (0)