diff --git a/.gitignore b/.gitignore index 6809ebb..ce55809 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ # Ignore environment variables .env +# Ignore Active Storage +/storage + # Ignore dragonfly uploads /public/system /public/packs diff --git a/Gemfile b/Gemfile index f7ae0a7..bf985e8 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem "rails", "5.2.1" gem "delayed_job_active_record" gem "dragonfly" gem "http" +gem "mini_magick" gem "omniauth-github" gem "pg" gem "puma" diff --git a/Gemfile.lock b/Gemfile.lock index a10b1af..abd0884 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,6 +121,7 @@ GEM mimemagic (~> 0.3.2) method_source (0.9.1) mimemagic (0.3.2) + mini_magick (4.9.2) mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) @@ -270,6 +271,7 @@ DEPENDENCIES geckodriver-helper http launchy + mini_magick omniauth-github pg pry @@ -289,4 +291,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.4 + 1.16.5 diff --git a/app/helpers/image_helper.rb b/app/helpers/image_helper.rb index 62e5ec7..0298353 100644 --- a/app/helpers/image_helper.rb +++ b/app/helpers/image_helper.rb @@ -1,9 +1,15 @@ module ImageHelper + def image_variant(image, variant) + image.variant(variant) + end + def image_thumb(image, size) - if image.format == "jpeg" - image.thumb(size).encode("jpg", "-quality 90") - else - image.thumb(size) - end + image.variant( + combine_options: { + gravity: "center", + resize: "#{size}x#{size}^", + extent: "#{size}x#{size}", + }, + ) end end diff --git a/app/models/image.rb b/app/models/image.rb index 379ff1a..1e31197 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -1,5 +1,6 @@ class Image < ActiveRecord::Base - dragonfly_accessor :image + dragonfly_accessor :df_image + has_one_attached :image validates :image, presence: true diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index 43a3604..31ca994 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -1,17 +1,17 @@ - " + " media="(min-width: 960px) and (-webkit-min-device-pixel-ratio: 2), (min-width: 960px) and (min-resolution: 192dpi)"> - " + " media="(min-width: 960px)"> - " + " media="(min-width: 640px) and (-webkit-min-device-pixel-ratio: 2), (min-width: 640px) and (min-resolution: 192dpi)"> - " + " media="(min-width: 640px)"> - " + " media="(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)"> - "> - " itemprop="image"> + "> + " itemprop="image"> diff --git a/app/views/images/index.html.erb b/app/views/images/index.html.erb index 803ed02..6b6d926 100644 --- a/app/views/images/index.html.erb +++ b/app/views/images/index.html.erb @@ -5,7 +5,7 @@