Skip to content

Commit

Permalink
Use WebP for all thumbnails
Browse files Browse the repository at this point in the history
WebP is well supported and is much more efficient than
png or jpg.
  • Loading branch information
tvdeyen committed Jan 8, 2024
1 parent b068ac6 commit 5ba02c1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/alchemy/picture_thumbnails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def thumbnail_url_options
crop_from: crop && crop_from.presence || default_crop_from&.join("x"),
crop_size: crop && crop_size.presence || default_crop_size&.join("x"),
flatten: true,
format: picture&.image_file_format || "jpg"
format: "webp"
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pictures/_picture.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</sl-tooltip>
</span>
<% end %>
<% picture_url = picture.url(size: preview_size(@size), flatten: true) %>
<% picture_url = picture.url(size: preview_size(@size), flatten: true, format: "webp") %>
<% image = image_tag(picture_url || "alchemy/missing-image.svg", alt: picture.name) %>
<% if can?(:edit, picture) && picture_url %>
<%= link_to(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<sl-tooltip content="<%= Alchemy.t(:assign_image) %>">
<%= link_to(
image_tag(
picture_to_assign.url(size: preview_size(size), flatten: true) || "alchemy/missing-image.svg",
picture_to_assign.url(size: preview_size(size), flatten: true, format: "webp") || "alchemy/missing-image.svg",
alt: picture_to_assign.name
),
alchemy.assign_admin_picture_path(
Expand Down
12 changes: 6 additions & 6 deletions lib/alchemy/test_support/having_picture_thumbnails_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@
allow(record).to receive(:settings) { settings }
end

it "includes the image's original file format." do
expect(thumbnail_url).to match(/\.png/)
it "includes webp file format." do
expect(thumbnail_url).to match(/\.webp/)
end

it "flattens the image." do
Expand Down Expand Up @@ -305,8 +305,8 @@
create(:alchemy_picture)
end

it "includes the image's original file format." do
expect(thumbnail_url_options[:format]).to eq("png")
it "uses webp image format." do
expect(thumbnail_url_options[:format]).to eq("webp")
end

it "flattens the image." do
Expand Down Expand Up @@ -381,7 +381,7 @@
crop_from: nil,
crop_size: nil,
flatten: true,
format: "jpg",
format: "webp",
size: "160x120"
)
end
Expand All @@ -400,7 +400,7 @@
crop_from: nil,
crop_size: nil,
flatten: true,
format: "jpg",
format: "webp",
size: "160x120"
)
end
Expand Down

0 comments on commit 5ba02c1

Please sign in to comment.