about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--flake.nix3
-rwxr-xr-xgal9
2 files changed, 9 insertions, 3 deletions
diff --git a/flake.nix b/flake.nix
index 5fb1688..4958116 100644
--- a/flake.nix
+++ b/flake.nix
@@ -7,7 +7,7 @@
     with import nixpkgs { system = "x86_64-linux"; };
     stdenv.mkDerivation {
       pname = "gal";
-      version = "0.1";
+      version = "0.2";
 
       src = self;
 
@@ -17,6 +17,7 @@
         cp style.css $out/share/gal
 
         sed -i 's:convert:${imagemagick}/bin/convert:g' $out/bin/gal
+        sed -i 's:cwebp:${libwebp}/bin/cwebp:g' $out/bin/gal
         sed -i "s:cp style.css:cp $out/share/gal/style.css:g" $out/bin/gal
       '';
     };
diff --git a/gal b/gal
index b7a5c5f..80d6478 100755
--- a/gal
+++ b/gal
@@ -48,7 +48,11 @@ for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
   [ -f $f ] && cat >> $OUTPUT/index.html <<EOF
       <div class="tile">
         <a href="photos/$filename">
-          <img src="thumbs/$filename" alt="$filename" />
+          <picture>
+            <source srcset="thumbs/${filename%.*}.webp" type="image/webp">
+            <source srcset="thumbs/$filename" type="image/${filename##*.}">
+            <img src="thumbs/$filename" alt="$filename" />
+          </picture>
         </a>
       </div>
 EOF
@@ -81,5 +85,6 @@ for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
   filename=$(basename $f)
   echo "Optimizing $filename"
   [ -f $f ] && convert -auto-orient -strip -quality $QUALITY -resize x$RESOLUTION "$f" "$OUTPUT/photos/$filename" && \
-    convert -auto-orient -strip -quality $QUALITY -resize x$THUMBNAIL_RESOLUTION "$f" "$OUTPUT/thumbs/$filename"
+    convert -auto-orient -strip -quality $QUALITY -resize x$THUMBNAIL_RESOLUTION "$f" "$OUTPUT/thumbs/$filename" && \
+    cwebp -q $QUALITY "$OUTPUT/thumbs/$filename" -o "$OUTPUT/thumbs/${filename%.*}.webp"
 done