blob: 06a516928abe8101180af42963061c604fc7e839 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
create_photo_derivatives() {
local -r photos_dir="$1"; shift
local -r thumbs_dir="$1"; shift
local -r blurs_dir="$1"; shift
local -r photo="$1"; shift
local dirname
local height
if [[ -f "$DIST_DIR/$thumbs_dir/$photo" \
&& -f "$DIST_DIR/$blurs_dir/$photo" ]]; then
log_verbose "Skipped existing thumb and blur" \
"$(_display_path "$DIST_DIR/$thumbs_dir/$photo") and" \
"$(_display_path "$DIST_DIR/$blurs_dir/$photo")"
return
fi
dirname="$DIST_DIR/$thumbs_dir"
mkdir -p "$dirname"
log_info "Creating thumb $(_display_path "$DIST_DIR/$thumbs_dir/$photo")"
# Double the height, as CSS scales images based on boxing too.
height=$(( THUMBHEIGHT * 2 ))
imagemagick \
"$DIST_DIR/$photos_dir/$photo" \
-geometry "x$height" \
"$DIST_DIR/$thumbs_dir/$photo"
dirname="$DIST_DIR/$blurs_dir"
mkdir -p "$dirname"
log_info "Creating blur $(_display_path "$DIST_DIR/$blurs_dir/$photo")"
imagemagick \
"$DIST_DIR/$thumbs_dir/$photo" \
-flip \
-blur 0x8 \
"$DIST_DIR/$blurs_dir/$photo"
}
create_all_photo_derivatives() {
local -r photos_dir="$1"; shift
local -r thumbs_dir="$1"; shift
local -r blurs_dir="$1"; shift
local photo
# Throttled background job pool (max IMAGE_JOBS concurrent), addressed by the
# single handle "image_jobs". job_pool_wait returns 1 if any job failed.
job_pool_init image_jobs
while IFS= read -r photo; do
job_pool_submit image_jobs "image derivative job for photo $photo" \
create_photo_derivatives "$photos_dir" "$thumbs_dir" "$blurs_dir" \
"$photo"
done < <(list_photos "$photos_dir")
job_pool_wait image_jobs
}
prepare_generation_photo_assets() {
warn_unsupported_incoming_files
mkdir -p "$DIST_DIR/photos"
cleanphotos
scalephotos
create_all_photo_derivatives 'photos' 'thumbs' 'blurs'
}
|