* feat/WIP: first version of the svg logo to png logo DUS * feat: logoSVG Uploader * refactor: remove the if original_filename * feat: add a test for the logo_svg_uploader * feat: update the test and dus * add soem error handling * updae the rails spec helper * feat: provide a content type * feat: add content type * Try https://travis-ci.community/t/build-times-out-with-no-apparent-reason/5083/4 * chore: try this suggestion https://stackoverflow.com/questions/41138404/how-to-install-newer-imagemagick-with-webp-support-in-travis-ci-container * chore: remove libweb adn fix = in the travis.yml * chore: undo the changes to attempt to update the version for image magick * feat: install gsfonts for convert * chore: add a comment for svg * feat: use the good practices for tempfile, update error handling and update the tests * chore: update the timestamp on the DUS * feat: convert to png with a transparent background using Image Magick * feat: substitute some css variables with real css colors * chore: revert the path * fix: set content type * Update lib/data_update_scripts/20220105112823_migrate_logo_svg_data.rb Co-authored-by: Jamie Gaskins <jamie@forem.com> Co-authored-by: Jamie Gaskins <jamie@forem.com>
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
class BaseUploader < CarrierWave::Uploader::Base
|
|
include CarrierWave::BombShelter # limits size to 4096x4096
|
|
include CarrierWave::MiniMagick # adds processing operations
|
|
|
|
EXTENSION_ALLOWLIST = %w[jpg jpeg jpe gif png ico bmp dng].freeze
|
|
FRAME_MAX = 500
|
|
FRAME_STRIP_MAX = 150
|
|
|
|
process :validate_frame_count
|
|
process :strip_exif
|
|
|
|
def store_dir
|
|
# eg. uploads/user/profile_image/1/e481b7ee.jpg
|
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
end
|
|
|
|
def extension_allowlist
|
|
EXTENSION_ALLOWLIST
|
|
end
|
|
|
|
def size_range
|
|
1..(25.megabytes)
|
|
end
|
|
|
|
protected
|
|
|
|
# strip EXIF (and GPS) data
|
|
def strip_exif
|
|
# There will be no exif data for an SVG
|
|
return if file.content_type.include?("svg")
|
|
|
|
manipulate! do |image|
|
|
image.strip unless image.frames.count > FRAME_STRIP_MAX
|
|
image = yield(image) if block_given?
|
|
image
|
|
end
|
|
end
|
|
|
|
def validate_frame_count
|
|
begin
|
|
return unless MiniMagick::Image.new(file.path).frames.count > FRAME_MAX
|
|
rescue Timeout::Error
|
|
raise CarrierWave::IntegrityError, "Image processing timed out."
|
|
end
|
|
|
|
raise CarrierWave::IntegrityError, "GIF contains too many frames. Max frame count allowed is #{FRAME_MAX}."
|
|
end
|
|
end
|