logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

account_header.rb (1072B)


  1. # frozen_string_literal: true
  2. module AccountHeader
  3. extend ActiveSupport::Concern
  4. IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze
  5. LIMIT = 2.megabytes
  6. class_methods do
  7. def header_styles(file)
  8. styles = { original: { geometry: '700x335#', file_geometry_parser: FastGeometryParser } }
  9. styles[:static] = { geometry: '700x335#', format: 'png', convert_options: '-coalesce', file_geometry_parser: FastGeometryParser } if file.content_type == 'image/gif'
  10. styles
  11. end
  12. private :header_styles
  13. end
  14. included do
  15. # Header upload
  16. has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-strip' }, processors: [:lazy_thumbnail]
  17. validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
  18. validates_attachment_size :header, less_than: LIMIT
  19. remotable_attachment :header, LIMIT
  20. end
  21. def header_original_url
  22. header.url(:original)
  23. end
  24. def header_static_url
  25. header_content_type == 'image/gif' ? header.url(:static) : header_original_url
  26. end
  27. end