Skip to content

Commit

Permalink
chore: Replace all quality notations in image variants
Browse files Browse the repository at this point in the history
The default is now vips, rather than image_magick
  • Loading branch information
Mitcheljager committed Nov 22, 2024
1 parent a2c76d8 commit 763c34b
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def active_storage_blob_variant_url
if params[:type] == "video"
url = rails_public_blob_url(blob)
elsif params[:type] == "thumbnail"
url = rails_public_blob_url(blob.variant(quality: 95, resize_to_fill: [200, 200 / 9 * 5], format: :webp).processed)
url = rails_public_blob_url(blob.variant(saver: { quality: 95 }, resize_to_fill: [200, 200 / 9 * 5], format: :webp).processed)
elsif params[:type] == "full"
url = rails_public_blob_url(blob.variant(quality: 95).processed)
url = rails_public_blob_url(blob.variant(saver: { quality: 95 }).processed)
else
url = rails_public_blob_url(blob.variant(quality: 95, resize_to_limit: [1920, 1080], format: :webp).processed)
url = rails_public_blob_url(blob.variant(saver: { quality: 95 }, resize_to_limit: [1920, 1080], format: :webp).processed)
end

render json: url, layout: false
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ def notify_discord(type)
revision = @revision
path = post_url(post.code.upcase)
user_path = user_url(post.user.username)
image = @ordered_images.present? && @ordered_images.first.present? ? url_for(@ordered_images.first.variant(quality: 95).processed.url) : ""
avatar = @post.user.profile_image.present? ? url_for(@post.user.profile_image.variant(quality: 95, resize_to_fill: [120, 120]).processed.url) : ""
image = @ordered_images.present? && @ordered_images.first.present? ? url_for(@ordered_images.first.variant(saver: { quality: 95 }).processed.url) : ""
avatar = @post.user.profile_image.present? ? url_for(@post.user.profile_image.variant(saver: { quality: 95 }, resize_to_fill: [120, 120]).processed.url) : ""
content = ActionController::Base.helpers.strip_tags(post.description).truncate(type == "New" ? 500 : 250)

embed = Discord::Embed.new do
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/posts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def url_for_post_thumbnail(post, width = 120, height = 68, size = "small")
image = post.images.find_by_blob_id(JSON.parse(post.image_order).first)

if image
url = rails_public_blob_url(image.variant(quality: 90, resize_to_fill: [width, height], format: :webp).processed)
url = rails_public_blob_url(image.variant(saver: { quality: 90 }, resize_to_fill: [width, height], format: :webp).processed)
end
rescue
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/post_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def thumbnail
image = object.images.find_by_blob_id(JSON.parse(object.image_order).first)

if image
url = rails_public_blob_url(image.variant(quality: 95, resize_to_fill: [690, 394]).processed)
url = rails_public_blob_url(image.variant(saver: { quality: 95 }, resize_to_fill: [690, 394]).processed)
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/views/application/_body_bg.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<% if yield(:replace_body_bg) == "user" %>
<source
srcset="
<%= rails_public_blob_url(@user.banner_image.variant(quality: 90, resize_to_fill: [640, 400]).processed) %> 640w,
<%= rails_public_blob_url(@user.banner_image.variant(quality: 90, resize_to_fill: [960, 400]).processed) %> 960w,
<%= rails_public_blob_url(@user.banner_image.variant(quality: 90, resize_to_fill: [1920, 400]).processed) %> 1920w"
<%= rails_public_blob_url(@user.banner_image.variant(saver: { quality: 90 }, resize_to_fill: [640, 400]).processed) %> 640w,
<%= rails_public_blob_url(@user.banner_image.variant(saver: { quality: 90 }, resize_to_fill: [960, 400]).processed) %> 960w,
<%= rails_public_blob_url(@user.banner_image.variant(saver: { quality: 90 }, resize_to_fill: [1920, 400]).processed) %> 1920w"
type="image/jpg">

<%= image_tag rails_public_blob_url(@user.banner_image.variant(quality: 90, resize_to_fill: [1920, 400]).processed) %>
<%= image_tag rails_public_blob_url(@user.banner_image.variant(saver: { quality: 90 }, resize_to_fill: [1920, 400]).processed) %>
<% end %>
</picture>
</div>
4 changes: 2 additions & 2 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% content_for :page_title, @article.title %>
<% content_for :og_description, strip_tags(markdown(@article.content || "")).truncate(200).gsub("\n"," ") %>
<% content_for :og_summary_small, "true" %>
<% begin %><% content_for :og_image, "#{ rails_public_blob_url(@article.cover_image.variant(quality: 95, resize_to_fill: [900, 500]).processed) if @article.cover_image.present? }" %><% rescue %><% end %>
<% begin %><% content_for :og_image, "#{ rails_public_blob_url(@article.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500]).processed) if @article.cover_image.present? }" %><% rescue %><% end %>
<% cache @article do %>
<article class="blog">
Expand All @@ -16,7 +16,7 @@
<div class="blog__image">
<% if @article.cover_image.attached? %>
<% begin %>
<%= image_tag rails_public_blob_url(@article.cover_image.variant(quality: 95, resize_to_fill: [900, 500]).processed), loading: "lazy", alt: @article.title, width: 900, height: 500 %>
<%= image_tag rails_public_blob_url(@article.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500]).processed), loading: "lazy", alt: @article.title, width: 900, height: 500 %>
<% rescue %>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/blocks/post/_gallery.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="gallery gallery--<%= block.id %>">
<% images.each do |image| %>
<% next unless image %>
<% url = rails_public_blob_url(image.variant(quality: 95).processed) %>
<% url = rails_public_blob_url(image.variant(saver: { quality: 95 }).processed) %>

<div class="gallery__item" data-action="show-modal set-gallery" data-target="gallery-<%= random_id %>" data-url="<%= url %>">
<%= image_tag url, alt: "", loading: "lazy" %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/collections/_collection_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="collection__image">
<% if collection.cover_image.attached? %>
<%= link_to collection_path(collection.nice_url), title: collection.title do %>
<% image_url = rails_public_blob_url(collection.cover_image.variant(quality: 95, resize_to_fill: [450, 250], format: :webp).processed) %>
<% image_url = rails_public_blob_url(collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [450, 250], format: :webp).processed) %>
<%= image_tag image_url,
srcset: "
#{ image_url } 1x,
#{ rails_public_blob_url(collection.cover_image.variant(quality: 95, resize_to_fill: [900, 500], format: :webp).processed) } 2x",
#{ rails_public_blob_url(collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500], format: :webp).processed) } 2x",
alt: collection.title,
width: 450,
height: 250,
Expand Down
2 changes: 1 addition & 1 deletion app/views/collections/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<%= form.label :cover_image, "Cover image", class: "form-label" %>

<div class="cover-image well well--dark block">
<%= image_tag (@collection.cover_image.attached? ? rails_public_blob_url(@collection.cover_image.variant(quality: 95, resize_to_fill: [900, 500]).processed) : "//:0"),
<%= image_tag (@collection.cover_image.attached? ? rails_public_blob_url(@collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500]).processed) : "//:0"),
data: { image_preview: "cover" },
class: "img-fluid" %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/collections/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<% content_for :page_title, "#{ @collection.title } #{ "| Page #{ params[:page] }" if params[:page] }" %>
<% begin %><% content_for :og_image, "#{ rails_public_blob_url(@collection.cover_image.variant(quality: 95, resize_to_fill: [900, 500]).processed) if @collection.cover_image.attached? }" %><% rescue %><% end %>
<% begin %><% content_for :og_image, "#{ rails_public_blob_url(@collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500]).processed) if @collection.cover_image.attached? }" %><% rescue %><% end %>
<% if @collection.cover_image.attached? %>
<% begin %>
<div class="relative">
<% ["", "background-blur background-blur--visible"].each do |classes| %>
<picture class="<%= classes %>">
<source media="(min-width: 560px)" srcset="<%= rails_public_blob_url(@collection.cover_image.variant(quality: 95, resize_to_fill: [900, 500], format: :webp).processed) %>" type="image/webp">
<source media="(min-width: 0px)" srcset="<%= rails_public_blob_url(@collection.cover_image.variant(quality: 95, resize_to_fill: [450, 250], format: :webp).processed) %>" type="image/webp">
<img class="img-fluid cover-image" src="<%= rails_public_blob_url(@collection.cover_image.variant(quality: 95, resize_to_fill: [900, 500], format: :webp).processed) %>" alt="<%= @collection.title %>" width="900" height="500" loading="lazy" />
<source media="(min-width: 560px)" srcset="<%= rails_public_blob_url(@collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500], format: :webp).processed) %>" type="image/webp">
<source media="(min-width: 0px)" srcset="<%= rails_public_blob_url(@collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [450, 250], format: :webp).processed) %>" type="image/webp">
<img class="img-fluid cover-image" src="<%= rails_public_blob_url(@collection.cover_image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500], format: :webp).processed) %>" alt="<%= @collection.title %>" width="900" height="500" loading="lazy" />
</picture>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/filter/get_verified_users.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= link_to build_filter_path(:author, user.username), class: "dropdown__item dropdown__item--thin", data: { action: "add-filter", value: CGI.escape(user.username) } do %>
<% if user.profile_image.attached? %>
<%= image_tag rails_public_blob_url(user.profile_image.variant(quality: 95, resize_to_fill: [30, 30]).processed), width: 30, height: 30, loading: "lazy" %>
<%= image_tag rails_public_blob_url(user.profile_image.variant(saver: { quality: 95 }, resize_to_fill: [30, 30]).processed), width: 30, height: 30, loading: "lazy" %>
<% else %>
<span class="empty-image"></span>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_carousel.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<% @ordered_images.each_with_index do |image, index| %>
<button class="carousel__navigation-item <%= "carousel__navigation-item--is-active" if index == 0 %>" data-action="carousel-go-to" data-target="<%= @post.carousel_video.present? ? index + 1 : index %>">
<%= image_tag rails_public_blob_url(image.variant(quality: 95, resize_to_fill: [120, 120], format: :webp).processed), height: 120, width: 120, alt: "" %>
<%= image_tag rails_public_blob_url(image.variant(saver: { quality: 95 }, resize_to_fill: [120, 120], format: :webp).processed), height: 120, width: 120, alt: "" %>
</button>
<% end %>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/posts/_carousel_item.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% preload ||= false %>
<% image_small = rails_public_blob_url(image.variant(quality: 95, resize_to_fill: [450, 250], format: :webp).processed) %>
<% image_large = rails_public_blob_url(image.variant(quality: 95, resize_to_fill: [900, 500], format: :webp).processed) %>
<% image_small = rails_public_blob_url(image.variant(saver: { quality: 95 }, resize_to_fill: [450, 250], format: :webp).processed) %>
<% image_large = rails_public_blob_url(image.variant(saver: { quality: 95 }, resize_to_fill: [900, 500], format: :webp).processed) %>
<% image_breakpoint = 560 %>
<% content_for :preload do %>
Expand All @@ -27,7 +27,7 @@
class="button button--small button--secondary"
data-action="show-modal set-gallery"
data-target="carousel-modal"
data-url="<%= rails_public_blob_url(image.variant(quality: 95).processed) %>">
data-url="<%= rails_public_blob_url(image.variant(saver: { quality: 95 }).processed) %>">
View original size
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/posts/form/_image_upload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<%= svelte_component("Dropzone", {
images: (@ordered_images || {}).map { |i| {
id: i.blob_id,
url: rails_public_blob_url(i.variant(quality: 95, resize_to_fill: [200, 200 / 9 * 5]).processed),
preview_url: rails_public_blob_url(i.variant(quality: 95).processed)
url: rails_public_blob_url(i.variant(saver: { quality: 95 }, resize_to_fill: [200, 200 / 9 * 5]).processed),
preview_url: rails_public_blob_url(i.variant(saver: { quality: 95 }).processed)
} },
label: "Drop images here to add them to your post",
help: "Images will be displayed in a 900x500 format (max 2MB per image, jpeg/png only)",
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% content_for :page_title, @post.title %>
<% begin %><% content_for :og_image, rails_public_blob_url(@ordered_images.first.variant(quality: 95, resize_to_fill: [900, 500]).processed) if @ordered_images.present? && @ordered_images.any? %><% rescue %><% end %>
<% begin %><% content_for :og_image, rails_public_blob_url(@ordered_images.first.variant(saver: { quality: 95 }, resize_to_fill: [900, 500]).processed) if @ordered_images.present? && @ordered_images.any? %><% rescue %><% end %>
<% content_for :og_description, strip_tags(markdown(@post.description || "")).truncate(200).gsub("\n"," ") %>
<% content_for :bg_size, "medium" %>

Expand Down
4 changes: 2 additions & 2 deletions app/views/profiles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<%= form.label :profile_image, "Profile image", class: "form-label" %>

<div class="profile-image">
<%= image_tag (@user.profile_image.attached? ? rails_public_blob_url(@user.profile_image.variant(quality: 95, resize_to_fill: [140, 140]).processed) : "//:0"),
<%= image_tag (@user.profile_image.attached? ? rails_public_blob_url(@user.profile_image.variant(saver: { quality: 95 }, resize_to_fill: [140, 140]).processed) : "//:0"),
data: { image_preview: "profile-image" } %>
</div>

Expand All @@ -82,7 +82,7 @@
This image is displayed at the top of your profile.
</p>

<%= image_tag (@user.banner_image.attached? ? rails_public_blob_url(@user.banner_image.variant(quality: 90, resize_to_fill: [1920, 400]).processed) : "//:0"),
<%= image_tag (@user.banner_image.attached? ? rails_public_blob_url(@user.banner_image.variant(saver: { quality: 90 }, resize_to_fill: [1920, 400]).processed) : "//:0"),
class: "mt-1/4 img-fluid",
data: { image_preview: "banner" } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/profiles/_image.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if user.profile_image.attached? %>
<% begin %>
<%= image_tag rails_public_blob_url(user.profile_image.variant(quality: 95, resize_to_fill: [size, size]).processed), loading: "lazy", aria: { label: "Profile image of '#{ user.username }'" }, height: size, width: size %>
<%= image_tag rails_public_blob_url(user.profile_image.variant(saver: { quality: 95 }, resize_to_fill: [size, size]).processed), loading: "lazy", aria: { label: "Profile image of '#{ user.username }'" }, height: size, width: size %>
<% rescue %>
<% end %>
<% end %>

0 comments on commit 763c34b

Please sign in to comment.