about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-10-13 11:29:19 +0200
committerGitHub <noreply@github.com>2022-10-13 11:29:19 +0200
commitb04633a9614609f18b39ba0f0015df301a04ab64 (patch)
treec2cc9a8f4998e1e258f828d3d9d8db4440b10d8a /app/models
parent7afc6a630c76fb071bd189af3ac1366efc82f819 (diff)
Add image processing and generate blurhash for server thumbnail (#19348)
Remove separate server hero setting
Diffstat (limited to 'app/models')
-rw-r--r--app/models/form/admin_settings.rb2
-rw-r--r--app/models/site_upload.rb27
2 files changed, 26 insertions, 3 deletions
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb
index 7bd9e3743..b6bb3d795 100644
--- a/app/models/form/admin_settings.rb
+++ b/app/models/form/admin_settings.rb
@@ -22,7 +22,6 @@ class Form::AdminSettings
     custom_css
     profile_directory
     thumbnail
-    hero
     mascot
     trends
     trendable_by_default
@@ -49,7 +48,6 @@ class Form::AdminSettings
 
   UPLOAD_KEYS = %i(
     thumbnail
-    hero
     mascot
   ).freeze
 
diff --git a/app/models/site_upload.rb b/app/models/site_upload.rb
index cf10b30fc..d3b81d4d5 100644
--- a/app/models/site_upload.rb
+++ b/app/models/site_upload.rb
@@ -12,10 +12,35 @@
 #  meta              :json
 #  created_at        :datetime         not null
 #  updated_at        :datetime         not null
+#  blurhash          :string
 #
 
 class SiteUpload < ApplicationRecord
-  has_attached_file :file
+  include Attachmentable
+
+  STYLES = {
+    thumbnail: {
+      '@1x': {
+        format: 'png',
+        geometry: '1200x630#',
+        file_geometry_parser: FastGeometryParser,
+        blurhash: {
+          x_comp: 4,
+          y_comp: 4,
+        }.freeze,
+      },
+
+      '@2x': {
+        format: 'png',
+        geometry: '2400x1260#',
+        file_geometry_parser: FastGeometryParser,
+      }.freeze,
+    }.freeze,
+
+    mascot: {}.freeze,
+  }.freeze
+
+  has_attached_file :file, styles: ->(file) { STYLES[file.instance.var.to_sym] }, convert_options: { all: '-coalesce -strip' }, processors: [:lazy_thumbnail, :blurhash_transcoder, :type_corrector]
 
   validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/
   validates :file, presence: true