Skip to content

Commit

Permalink
Use WebP responsive images (alshedivat#498)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rohandebsarkar authored and semicolonsnet committed Oct 24, 2022
1 parent cfd22d2 commit 478a658
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
31 changes: 17 additions & 14 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,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
Expand Down Expand Up @@ -200,21 +200,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
Expand Down
17 changes: 17 additions & 0 deletions _includes/figure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% assign path = include.path | remove: ".jpg" | remove: ".jpeg" | remove: ".png" | remove: ".tiff" %}

<figure>

<picture>
{% for i in site.imagemagick.widths %}
<source media="(max-width: {{ i }}px)" srcset="{{ path | relative_url }}-{{ i }}.webp">
{% endfor %}

<!-- Fallback to the original file -->
<img {% if include.class %}class="{{ include.class }}"{% endif %} src="{{ include.path | relative_url }}" {% if include.alt %}alt="{{ alt }}"{% endif %} {% if include.title %}title="{{ title }}"{% endif %} {% if include.zoomable %}data-zoomable{% endif %} />

</picture>

{% if include.caption %}<figcaption class="caption">{{ include.caption }}</figcaption>{% endif %}

</figure>
9 changes: 4 additions & 5 deletions _layouts/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ <h1 class="post-title">
{% if page.profile %}
<div class="profile float-{% if page.profile.align == 'left' %}left{% else %}right{% endif %}">
{% 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 %}
<div class="address">
Expand Down

0 comments on commit 478a658

Please sign in to comment.