Skip to content

Commit

Permalink
Set admin picture thumbnail quality to 90
Browse files Browse the repository at this point in the history
Make the picture thumbnail quality independent from the
frontend output_image_quality config.

Using 90 as value for quality should be a good compromise
between file size and image quality.

The same image with quality of 100 is three times the size of an image with quality of 90 while having nearly the same image
quality for a small thumbnail. An large thumbnail (as used in the
image cropper) is ten times the size in 100% quality!
  • Loading branch information
tvdeyen committed Jan 16, 2024
1 parent ffc776e commit bf6263a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

module Alchemy
class Picture < BaseRecord
THUMBNAIL_QUALITY = 90

THUMBNAIL_SIZES = {
small: "80x60",
medium: "160x120",
Expand Down Expand Up @@ -195,14 +197,16 @@ def url(options = {})
# Returns an url for the thumbnail representation of the picture
#
# @param [String] size - The size of the thumbnail
# @param [Integer] quality - The quality of the thumbnail
#
# @return [String]
def thumbnail_url(size: "160x120")
def thumbnail_url(size: "160x120", quality: THUMBNAIL_QUALITY)
return if image_file.nil?

url(
flatten: true,
format: "webp",
quality: quality,
size: size
)
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/alchemy/picture_thumbnails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ 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: "webp"
format: "webp",
quality: Alchemy::Picture::THUMBNAIL_QUALITY
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
crop_size: nil,
flatten: true,
format: "webp",
quality: Alchemy::Picture::THUMBNAIL_QUALITY,
size: "160x120"
)
end
Expand All @@ -401,6 +402,7 @@
crop_size: nil,
flatten: true,
format: "webp",
quality: Alchemy::Picture::THUMBNAIL_QUALITY,
size: "160x120"
)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/models/alchemy/picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ module Alchemy
expect(picture).to receive(:url).with(
flatten: true,
format: "webp",
quality: Alchemy::Picture::THUMBNAIL_QUALITY,
size: "160x120"
)
thumbnail_url
Expand All @@ -347,11 +348,26 @@ module Alchemy
expect(picture).to receive(:url).with(
flatten: true,
format: "webp",
quality: Alchemy::Picture::THUMBNAIL_QUALITY,
size: "800x600"
)
thumbnail_url
end
end

context "with quality given" do
subject(:thumbnail_url) { picture.thumbnail_url(quality: 50) }

it "returns the url to the thumbnail" do
expect(picture).to receive(:url).with(
flatten: true,
format: "webp",
quality: 50,
size: "160x120"
)
thumbnail_url
end
end
end
end

Expand Down

0 comments on commit bf6263a

Please sign in to comment.