Browse Source

include web-image-resize and call automatically if needed

Thomas Buck 1 year ago
parent
commit
af93510f1b
2 changed files with 63 additions and 1 deletions
  1. 31
    1
      macros.py
  2. 32
    0
      web-image-resize

+ 31
- 1
macros.py View File

@@ -208,7 +208,8 @@ def printRobotMenuDeutsch():
208 208
 # lightgallery helper macro
209 209
 # -----------------------------------------------------------------------------
210 210
 
211
-# call this macro like this
211
+# call this macro like this:
212
+
212 213
 # lightgallery([
213 214
 #     [ "image-link", "description" ],
214 215
 #     [ "image-link", "thumbnail-link", "description" ],
@@ -216,6 +217,34 @@ def printRobotMenuDeutsch():
216 217
 #     [ "video-link", "mime", "thumbnail-link", "image-link", "description" ]
217 218
 # ])
218 219
 
220
+# it will also auto-generate thumbnails and resize and strip EXIF from images
221
+# using the included web-image-resize script.
222
+
223
+def lightgallery_check_thumbnail(link, thumb):
224
+    # only check local image links
225
+    if not link.startswith('img/'):
226
+        return
227
+
228
+    # generate thumbnail filename web-image-resize will create
229
+    x = link.rfind('.')
230
+    img = link[:x] + '_small' + link[x:]
231
+
232
+    # only run when desired thumb path matches calculated ones
233
+    if thumb != img:
234
+        return
235
+
236
+    # generate fs path to images
237
+    path = os.path.join(os.getcwd(), 'static', link)
238
+    img = os.path.join(os.getcwd(), 'static', thumb)
239
+
240
+    # no need to generate thumb again
241
+    if os.path.exists(img):
242
+        return
243
+
244
+    # run web-image-resize to generate thumbnail
245
+    script = os.path.join(os.getcwd(), 'web-image-resize')
246
+    os.system(script + ' ' + path)
247
+
219 248
 def lightgallery(links):
220 249
     videos = [l for l in links if len(l) == 5]
221 250
     v_i = -1
@@ -240,6 +269,7 @@ def lightgallery(links):
240 269
                 link, alt = l
241 270
                 x = link.rfind('.')
242 271
                 img = link[:x] + '_small' + link[x:]
272
+            lightgallery_check_thumbnail(link, img)
243 273
             print '<div class="border" data-src="' + link + '"><a href="' + link + '"><img class="pic" src="' + img + '" alt="' + alt + '"></a></div>'
244 274
         elif len(l) == 5:
245 275
             v_i += 1

+ 32
- 0
web-image-resize View File

@@ -0,0 +1,32 @@
1
+#!/bin/bash
2
+
3
+if [ -z "$1" ]; then
4
+    echo "No argument supplied"
5
+    exit 1
6
+fi
7
+
8
+dir=$(dirname "${1}")
9
+image=$(basename -- "${1}")
10
+ext="${image##*.}"
11
+name="${image%.*}"
12
+thumb="${name}_small.${ext}"
13
+orig="${name}_bak.${ext}"
14
+
15
+echo "Directory : $dir"
16
+echo "Input file: $image"
17
+#echo "Backup    : $orig"
18
+echo "Thumbnail : $thumb"
19
+
20
+cd "$dir"
21
+
22
+echo cp $image $orig
23
+cp "$image" "$orig"
24
+
25
+echo convert "$orig" -auto-orient -resize 1600x1600\> -strip "$image"
26
+convert "$orig" -auto-orient -resize 1600x1600\> -strip "$image"
27
+
28
+echo convert "$image" -auto-orient -thumbnail 300x300\> -strip "$thumb"
29
+convert "$image" -auto-orient -thumbnail 300x300\> -strip "$thumb"
30
+
31
+echo rm -rf "$orig"
32
+rm -rf "$orig"

Loading…
Cancel
Save