Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Switch from mini_magick to Ruby VIPS
Damian Legawieca7329599b626
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 183f1e93c9..4da8338f11 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -27,6 +27,9 @@ run_tests: &run_testskeys:- spree-bundle-v10-ruby-2-7-{{ .Branch }}- spree-bundle-v10-ruby-2-7+ - run:+ name: Install libvips+ command: sudo apt-get install libvips- run:name: Ensure Bundle Installcommand: |@@ -53,6 +56,9 @@ run_tests_3_0: &run_tests_3_0keys:- spree-bundle-v10-ruby-3-0-{{ .Branch }}- spree-bundle-v10-ruby-3-0+ - run:+ name: Install libvips+ command: sudo apt-get install libvips- run:name: Ensure Bundle Installcommand: |@@ -79,6 +85,9 @@ jobs:keys:- spree-bundle-v10-ruby-2-7-{{ .Branch }}- spree-bundle-v10-ruby-2-7+ - run:+ name: Install libvips+ command: sudo apt-get install libvips- run:name: Bundle Installcommand: |@@ -97,6 +106,9 @@ jobs:keys:- spree-bundle-v10-ruby-3-0-{{ .Branch }}- spree-bundle-v10-ruby-3-0+ - run:+ name: Install libvips+ command: sudo apt-get install libvips- run:name: Bundle Installcommand: |@@ -197,6 +209,9 @@ jobs:keys:- spree-bundle-v10-ruby-3-0-{{ .Branch }}- spree-bundle-v10-ruby-3-0+ - run:+ name: Install libvips+ command: sudo apt-get install libvips- run:name: Ensure Bundle Installcommand: |diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex f2ec0c1ce2..9272c741b0 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -61,11 +61,11 @@ module SpreeDEPRECATIONimage_path ||= if current_store.logo.attached? && current_store.logo.variable?- main_app.url_for(current_store.logo.variant(resize: '244x104>'))+ main_app.url_for(current_store.logo.variant(resize_to_limit: [244, 104]))elsif current_store.logo.attached? && current_store.logo.image?main_app.url_for(current_store.logo)else- 'logo/spree_50.png'+ 'logo/spree_50.png'endpath = spree.respond_to?(:root_path) ? spree.root_path : main_app.root_pathdiff --git a/core/app/models/concerns/spree/image_methods.rb b/core/app/models/concerns/spree/image_methods.rbindex 439e0e2f55..9d02132c8e 100644--- a/core/app/models/concerns/spree/image_methods.rb+++ b/core/app/models/concerns/spree/image_methods.rb@@ -2,19 +2,21 @@ module Spreemodule ImageMethodsextend ActiveSupport::Concern- def generate_url(size:, gravity: 'center', quality: 80, background: 'show')+ def generate_url(size:, gravity: 'centre', quality: 80, background: [0, 0, 0])return if size.blank?+size = size.gsub(/\s+/, '')return unless size.match(/(\d+)x(\d+)/)- polymorphic_path(attachment.variant(- gravity: gravity,- resize: size,- extent: size,- background: background,- quality: quality.to_i- ), only_path: true)+ width, height = size.split('x').map(&:to_i)++ # FIXME: bring back support for background color++ polymorphic_path(+ attachment.variant(resize_and_pad: [width, height, { gravity: gravity }], saver: { quality: quality }),+ only_path: true+ )enddef original_urldiff --git a/core/app/models/spree/asset/support/active_storage.rb b/core/app/models/spree/asset/support/active_storage.rbindex c67f315d91..619a1f7b7d 100644--- a/core/app/models/spree/asset/support/active_storage.rb+++ b/core/app/models/spree/asset/support/active_storage.rb@@ -8,7 +8,7 @@ module Spreedef url(style)return placeholder(style) unless attachment.attached?- attachment.variant(resize: dimensions_for_style(style))+ attachment.variant(resize_to_limit: dimensions_for_style(style))enddef placeholder(style)@@ -16,7 +16,8 @@ module Spreeenddef dimensions_for_style(style)- self.class.styles.with_indifferent_access[style] || self.class.styles.with_indifferent_access[default_style]+ dimensions = self.class.styles.with_indifferent_access[style] || self.class.styles.with_indifferent_access[default_style]+ dimensions.split('x').map(&:to_i)endendenddiff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rbindex bb858a2306..c64dcfa566 100644--- a/core/app/models/spree/cms_section.rb+++ b/core/app/models/spree/cms_section.rb@@ -18,7 +18,7 @@ module Spreedefine_method("img_#{count}_#{size}") do |dimensions = nil|return if !send("image_#{count}").attached? || dimensions.nil?- send("image_#{count}").variant(resize: dimensions)+ send("image_#{count}").variant(resize_to_limit: dimensions.split('x').map(&:to_i))endendenddiff --git a/core/app/models/spree/image.rb b/core/app/models/spree/image.rbindex fe47d98598..158fb0a213 100644--- a/core/app/models/spree/image.rb+++ b/core/app/models/spree/image.rb@@ -13,7 +13,7 @@ module Spreedef stylesself.class.styles.map do |_, size|- width, height = size.chop.split('x')+ width, height = size.chop.split('x').map(&:to_i){url: generate_url(size: size),@@ -28,7 +28,7 @@ module Spreesize = self.class.styles[name]return unless size- width, height = size.chop.split('x')+ width, height = size.chop.split('x').map(&:to_i){url: generate_url(size: size),@@ -40,7 +40,7 @@ module Spreedef style_dimensions(name)size = self.class.styles[name]- width, height = size.chop.split('x')+ width, height = size.chop.split('x').map(&:to_i){width: width,diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex 078f1287f7..d587322093 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -178,7 +178,7 @@ module Spreedef faviconreturn unless favicon_image.attached?- favicon_image.variant(resize: '32x32')+ favicon_image.variant(resize_to_limit: [32, 32])enddef can_be_deleted?diff --git a/core/app/models/spree/taxon_image.rb b/core/app/models/spree/taxon_image.rbindex 5602966f71..60ab005b45 100644--- a/core/app/models/spree/taxon_image.rb+++ b/core/app/models/spree/taxon_image.rb@@ -6,10 +6,10 @@ module Spreedef stylesself.class.styles.map do |_, size|- width, height = size[/(\d+)x(\d+)/].split('x')+ width, height = size[/(\d+)x(\d+)/].split('x').map(&:to_i){- url: polymorphic_path(attachment.variant(resize: size), only_path: true),+ url: polymorphic_path(attachment.variant(resize_to_limit: [width, height]), only_path: true),width: width,height: height}diff --git a/core/config/initializers/active_storage.rb b/core/config/initializers/active_storage.rbindex 892e53f8aa..29d15e378d 100644--- a/core/config/initializers/active_storage.rb+++ b/core/config/initializers/active_storage.rb@@ -1 +1,2 @@Rails.application.config.active_storage.content_types_to_serve_as_binary.delete('image/svg+xml')+Rails.application.config.active_storage.variant_processor = :vipsdiff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rbindex 65800ec727..e35cbef8ce 100644--- a/core/lib/spree/core.rb+++ b/core/lib/spree/core.rb@@ -14,7 +14,7 @@ require 'friendly_id'require 'kaminari'require 'monetize'require 'paranoia'-require 'mini_magick'+require 'ruby-vips'require 'ransack'require 'state_machines-activerecord'require 'active_storage_validations'diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rbindex aaa480adc2..468bedea62 100644--- a/core/spec/models/spree/store_spec.rb+++ b/core/spec/models/spree/store_spec.rb@@ -608,7 +608,7 @@ describe Spree::Store, type: :model doit 'returns a resized favicon' doexpect(favicon_variation).to be_present- expect(favicon_variation.transformations.fetch(:resize)).to eq('32x32')+ expect(favicon_variation.transformations.fetch(:resize_to_limit)).to eq([32, 32])endenddiff --git a/core/spree_core.gemspec b/core/spree_core.gemspecindex 5adeeddb8d..e0a7029ada 100644--- a/core/spree_core.gemspec+++ b/core/spree_core.gemspec@@ -51,7 +51,6 @@ Gem::Specification.new do |s|s.add_dependency 'state_machines-activemodel', '~> 0.7's.add_dependency 'stringex's.add_dependency 'validates_zipcode'- s.add_dependency 'mini_magick', '~> 4.9', '>= 4.9.4's.add_dependency 'image_processing', '~> 1.2's.add_dependency 'active_storage_validations', '~> 0.9', '<= 0.9.5's.add_dependency 'activerecord-typedstore'diff --git a/emails/app/helpers/spree/mail_helper.rb b/emails/app/helpers/spree/mail_helper.rbindex 9860b2b96c..1dae324ca3 100644--- a/emails/app/helpers/spree/mail_helper.rb+++ b/emails/app/helpers/spree/mail_helper.rb@@ -26,7 +26,7 @@ module Spreedef logo_pathreturn default_logo unless store_logo.attached?- return main_app.url_for(store_logo.variant(resize: '244x104>')) if store_logo.variable?+ return main_app.url_for(store_logo.variant(resize_to_limit: [244, 104])) if store_logo.variable?return main_app.url_for(store_logo) if store_logo.image?end