From f2d1bd5d509ba8d03790024fbbe061c474d27e66 Mon Sep 17 00:00:00 2001 From: Paul Arterburn Date: Wed, 1 Nov 2023 11:48:49 -0600 Subject: [PATCH] Allow webp uploads --- app/models/entry.rb | 2 +- app/uploaders/image_uploader.rb | 8 ++++---- app/views/entries/edit.html.haml | 2 +- app/views/entries/new.html.haml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/entry.rb b/app/models/entry.rb index ee78e922..8a8ba212 100644 --- a/app/models/entry.rb +++ b/app/models/entry.rb @@ -13,7 +13,7 @@ class Entry < ActiveRecord::Base validates :date, presence: true, valid_date: true validates :image, file_size: { less_than_or_equal_to: 20.megabytes }, - file_content_type: { allow: ['image/gif', 'image/jpeg', 'image/jpg', 'application/octet-stream', 'image/png', 'image/heic', 'image/heif'] } + file_content_type: { allow: ['image/gif', 'image/jpeg', 'image/jpg', 'application/octet-stream', 'image/png', 'image/webp', 'image/heic', 'image/heif'] } alias_attribute :entry, :body diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 69f53a30..0274e551 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -7,7 +7,7 @@ class ImageUploader < CarrierWave::Uploader::Base process :clear_generic_content_type process :convert_to_jpg, if: :heic_image? - process :convert_to_jpg, if: :webp_image? + # process :convert_to_jpg, if: :webp_image? process resize_to_limit: [1200, 1200], quality: 90, if: :web_image? process :auto_orient, if: :web_image? @@ -27,9 +27,9 @@ def heic_image?(file) self.content_type.blank? || self.content_type == "application/octet-stream" || self.content_type == "image/heic" || self.content_type == "image/heif" || self.filename =~ /^.+\.(heic|HEIC|Heic|heif|HEIF|Heif)$/i end - def webp_image?(file) - self.content_type == "image/webp" || self.filename =~ /^.+\.(Webp|webp|WEBP)$/i - end + # def webp_image?(file) + # self.content_type == "image/webp" || self.filename =~ /^.+\.(Webp|webp|WEBP)$/i + # end def store_dir add_dev = "/development" unless Rails.env.production? diff --git a/app/views/entries/edit.html.haml b/app/views/entries/edit.html.haml index 63e99e39..e3cbc1ab 100644 --- a/app/views/entries/edit.html.haml +++ b/app/views/entries/edit.html.haml @@ -51,7 +51,7 @@ =image_code(@entry) - else = f.label :image, "Photo" - = f.file_field :image, accept: "image/png,image/gif,image/jpeg,image/heic,image/heif", multiple: true + = f.file_field :image, accept: "image/png,image/gif,image/jpeg,image/webp,image/heic,image/heif", multiple: true %br %div diff --git a/app/views/entries/new.html.haml b/app/views/entries/new.html.haml index 31ff552d..7022c308 100644 --- a/app/views/entries/new.html.haml +++ b/app/views/entries/new.html.haml @@ -57,7 +57,7 @@ =image_code(@entry) - else = f.label :image, "Photo" - = f.file_field :image, accept: "image/png,image/gif,image/jpeg,image/heic,image/heif", multiple: true + = f.file_field :image, accept: "image/png,image/gif,image/jpeg,image/webp,image/heic,image/heif", multiple: true %br %div