Expand cropping options for Imgproxy (#11044)
This commit is contained in:
parent
218713739b
commit
c817737748
3 changed files with 35 additions and 1 deletions
|
|
@ -38,11 +38,20 @@ module Images
|
|||
}.freeze
|
||||
|
||||
def self.imgproxy(img_src, **kwargs)
|
||||
options = DEFAULT_IMGPROXY_OPTIONS.merge(kwargs).reject { |_, v| v.blank? }
|
||||
translated_options = translate_cloudinary_options(kwargs)
|
||||
options = DEFAULT_IMGPROXY_OPTIONS.merge(translated_options).reject { |_, v| v.blank? }
|
||||
Imgproxy.config.endpoint ||= get_imgproxy_endpoint
|
||||
Imgproxy.url_for(img_src, options)
|
||||
end
|
||||
|
||||
def self.translate_cloudinary_options(options)
|
||||
if options[:crop] == "fill"
|
||||
options[:resizing_type] = "fill"
|
||||
end
|
||||
|
||||
options
|
||||
end
|
||||
|
||||
def self.imgproxy_enabled?
|
||||
Imgproxy.config.key.present? && Imgproxy.config.salt.present?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
module DataUpdateScripts
|
||||
class ResaveToBustCacheForImgproxy
|
||||
def run
|
||||
return unless ENV["FOREM_CONTEXT"] == "forem_cloud"
|
||||
|
||||
User.find_each do |user|
|
||||
CacheBuster.bust_user(user)
|
||||
end
|
||||
|
||||
Organization.find_each do |organization|
|
||||
CacheBuster.bust_organization(organization, organization.slug)
|
||||
end
|
||||
|
||||
Article.find_each(&:save)
|
||||
Comment.find_each(&:save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -77,4 +77,11 @@ RSpec.describe Images::Optimizer, type: :service do
|
|||
expect(imgproxy_url).to match(%r{/s:500:500/aHR0cHM6Ly9pLmlt/Z3VyLmNvbS9mS1lL/Z280LnBuZw})
|
||||
end
|
||||
end
|
||||
|
||||
describe "#translate_cloudinary_options" do
|
||||
it "Set resizing_type to fill if crop: fill is provided" do
|
||||
options = { width: 100, height: 100, crop: "fill" }
|
||||
expect(described_class.translate_cloudinary_options(options)).to include(resizing_type: "fill")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue