Skip to content

Commit

Permalink
Allow webp uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Nov 1, 2023
1 parent 312bf21 commit f2d1bd5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/entries/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/entries/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f2d1bd5

Please sign in to comment.