From 7560eee67f154526344c1c63e53f2ae5cef8b28c Mon Sep 17 00:00:00 2001 From: Rohan Deb Sarkar Date: Wed, 22 Dec 2021 13:43:52 +0530 Subject: [PATCH] Use WebP responsive images (#498) This PR replaces the jekyll-responsive-images with jekyll-imagemagick for responsive WebP images. WebP images are much smaller compared to PNG and JPEG, faster to load and most of the modern browsers recommend it. More information about WebP images: https://developers.google.com/speed/webp --- Gemfile | 2 +- _config.yml | 31 +++++++++++++++++-------------- _includes/figure.html | 17 +++++++++++++++++ _includes/projects.html | 7 +++---- _layouts/about.html | 9 ++++----- _posts/2015-05-15-images.md | 14 +++++++------- _projects/1_project.md | 16 ++++++++-------- _projects/2_project.md | 16 ++++++++-------- _projects/3_project.md | 16 ++++++++-------- _projects/4_project.md | 16 ++++++++-------- _projects/5_project.md | 16 ++++++++-------- _projects/6_project.md | 16 ++++++++-------- 12 files changed, 97 insertions(+), 79 deletions(-) create mode 100644 _includes/figure.html diff --git a/Gemfile b/Gemfile index 31a554ce2bec..716091cb7926 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,8 @@ group :jekyll_plugins do gem 'jekyll-email-protect' gem 'jekyll-feed' gem 'jekyll-github-metadata' + gem 'jekyll-imagemagick' gem 'jekyll-paginate-v2' - gem 'jekyll-responsive-image' gem 'jekyll-scholar' gem 'jekyll-sitemap' gem 'jekyll-target-blank' diff --git a/_config.yml b/_config.yml index 244b7d443247..7650f947472f 100644 --- a/_config.yml +++ b/_config.yml @@ -157,8 +157,8 @@ plugins: - jekyll-email-protect - jekyll-feed - jekyll-github-metadata + - jekyll-imagemagick - jekyll-paginate-v2 - - jekyll-responsive-image - jekyll/scholar - jekyll-sitemap - jekyll-target-blank @@ -221,21 +221,24 @@ scholar: # ----------------------------------------------------------------------------- -# Jekyll Responsive Images +# Responsive WebP Images # ----------------------------------------------------------------------------- -responsive_image: - template: _includes/responsive_img.html - # Quality to use when resizing images. - default_quality: 80 - sizes: - - width: 480 - - width: 800 - - width: 1400 - quality: 90 - # Strip EXIF and other JPEG profiles. Helps to minimize JPEG size. - strip: true - +imagemagick: + enabled: true + widths: + - 480 + - 800 + - 1400 + input_directories: + - assets/img + input_formats: + - ".jpg" + - ".jpeg" + - ".png" + - ".tiff" + output_formats: + webp: "-quality 75%" # ----------------------------------------------------------------------------- # Jekyll Diagrams diff --git a/_includes/figure.html b/_includes/figure.html new file mode 100644 index 000000000000..d07322d955da --- /dev/null +++ b/_includes/figure.html @@ -0,0 +1,17 @@ +{% assign path = include.path | remove: ".jpg" | remove: ".jpeg" | remove: ".png" | remove: ".tiff" %} + +
+ + + {% for i in site.imagemagick.widths %} + + {% endfor %} + + + + + + + {% if include.caption %}
{{ include.caption }}
{% endif %} + +
diff --git a/_includes/projects.html b/_includes/projects.html index 396690d754b1..bfac1d922d41 100644 --- a/_includes/projects.html +++ b/_includes/projects.html @@ -6,10 +6,9 @@ {% endif %}
{% if project.img %} - {% responsive_image_block %} - path: {{ project.img }} - alt: "project thumbnail" - {% endresponsive_image_block %} + {% include figure.html + path=project.img + alt="project thumbnail" %} {% endif %}

{{ project.title }}

diff --git a/_layouts/about.html b/_layouts/about.html index 8209cfb8d08b..1663006a9047 100644 --- a/_layouts/about.html +++ b/_layouts/about.html @@ -15,11 +15,10 @@

{% if page.profile %}
{% if page.profile.image %} - {% responsive_image_block %} - path: {{ page.profile.image | prepend: 'assets/img/' }} - class: "img-fluid z-depth-1 rounded" - alt: {{ page.profile.image }} - {% endresponsive_image_block %} + {% assign profile_image_path = page.profile.image | prepend: 'assets/img/' %} + {% include figure.html + path=profile_image_path + class="img-fluid z-dept-1 rounded"%} {% endif %} {% if page.profile.address %}
diff --git a/_posts/2015-05-15-images.md b/_posts/2015-05-15-images.md index 544bb2bc0319..0729fcb48d78 100644 --- a/_posts/2015-05-15-images.md +++ b/_posts/2015-05-15-images.md @@ -10,10 +10,10 @@ This is an example post with image galleries.
- {% responsive_image path: assets/img/9.jpg class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/9.jpg" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/7.jpg class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/7.jpg" class="img-fluid rounded z-depth-1" %}
@@ -25,10 +25,10 @@ Simply add `data-zoomable` to `` tags that you want to make zoomable.
- {% responsive_image path: assets/img/8.jpg class: "img-fluid rounded z-depth-1" zoomable: true %} + {% include figure.html path="assets/img/8.jpg" class="img-fluid rounded z-depth-1" zoomable=true %}
- {% responsive_image path: assets/img/10.jpg class: "img-fluid rounded z-depth-1" zoomable: true %} + {% include figure.html path="assets/img/10.jpg" class="img-fluid rounded z-depth-1" zoomable=true %}
@@ -36,12 +36,12 @@ The rest of the images in this post are all zoomable, arranged into different mi
- {% responsive_image path: assets/img/11.jpg class: "img-fluid rounded z-depth-1" zoomable: true %} + {% include figure.html path="assets/img/11.jpg" class="img-fluid rounded z-depth-1" zoomable=true %}
- {% responsive_image path: assets/img/12.jpg class: "img-fluid rounded z-depth-1" zoomable: true %} + {% include figure.html path="assets/img/12.jpg" class="img-fluid rounded z-depth-1" zoomable=true %}
- {% responsive_image path: assets/img/7.jpg class: "img-fluid rounded z-depth-1" zoomable: true %} + {% include figure.html path="assets/img/7.jpg" class="img-fluid rounded z-depth-1" zoomable=true %}
diff --git a/_projects/1_project.md b/_projects/1_project.md index 9b920a38fe0f..5a95b9ad20fc 100644 --- a/_projects/1_project.md +++ b/_projects/1_project.md @@ -22,13 +22,13 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/1.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/1.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/3.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/3.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -36,7 +36,7 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -50,10 +50,10 @@ You describe how you toiled, sweated, *bled* for your project, and then... you r
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -70,10 +70,10 @@ Here's the code for the last row of images above: ```html
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
``` diff --git a/_projects/2_project.md b/_projects/2_project.md index 1a61208a0a86..4a266145d23c 100644 --- a/_projects/2_project.md +++ b/_projects/2_project.md @@ -22,13 +22,13 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/1.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/1.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/3.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/3.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -36,7 +36,7 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -50,10 +50,10 @@ You describe how you toiled, sweated, *bled* for your project, and then... you r
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -70,10 +70,10 @@ Here's the code for the last row of images above: ```html
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
``` diff --git a/_projects/3_project.md b/_projects/3_project.md index f7dd8ad30753..56968db035be 100644 --- a/_projects/3_project.md +++ b/_projects/3_project.md @@ -23,13 +23,13 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/1.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/1.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/3.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/3.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -37,7 +37,7 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -51,10 +51,10 @@ You describe how you toiled, sweated, *bled* for your project, and then... you r
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -71,10 +71,10 @@ Here's the code for the last row of images above: ```html
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
``` diff --git a/_projects/4_project.md b/_projects/4_project.md index c7d587e71f26..96eeb0e66ac2 100644 --- a/_projects/4_project.md +++ b/_projects/4_project.md @@ -22,13 +22,13 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/1.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/1.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/3.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/3.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -36,7 +36,7 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -50,10 +50,10 @@ You describe how you toiled, sweated, *bled* for your project, and then... you r
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -70,10 +70,10 @@ Here's the code for the last row of images above: ```html
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
``` diff --git a/_projects/5_project.md b/_projects/5_project.md index 78697dfb2667..aa488109c78f 100644 --- a/_projects/5_project.md +++ b/_projects/5_project.md @@ -22,13 +22,13 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/1.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/1.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/3.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/3.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -36,7 +36,7 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -50,10 +50,10 @@ You describe how you toiled, sweated, *bled* for your project, and then... you r
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -70,10 +70,10 @@ Here's the code for the last row of images above: ```html
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
``` diff --git a/_projects/6_project.md b/_projects/6_project.md index 6b8719c624fb..3d8d04d512b0 100644 --- a/_projects/6_project.md +++ b/_projects/6_project.md @@ -22,13 +22,13 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/1.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/1.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/3.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/3.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -36,7 +36,7 @@ To give your project a background in the portfolio page, just add the img tag to
- {% responsive_image path: assets/img/5.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/5.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -50,10 +50,10 @@ You describe how you toiled, sweated, *bled* for your project, and then... you r
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
@@ -70,10 +70,10 @@ Here's the code for the last row of images above: ```html
- {% responsive_image path: assets/img/6.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/6.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
- {% responsive_image path: assets/img/11.jpg title: "example image" class: "img-fluid rounded z-depth-1" %} + {% include figure.html path="assets/img/11.jpg" title="example image" class="img-fluid rounded z-depth-1" %}
```