Class: Pageflow::ImageFile

Inherits:
ApplicationRecord show all
Includes:
ImageFileStateMachine, UploadedFile
Defined in:
app/models/pageflow/image_file.rb

Constant Summary collapse

STYLES =
lambda do |attachment|
  panorama_format = File.extname(attachment.original_filename) == '.png' ? :PNG : :JPG

  Pageflow
    .config.thumbnail_styles
    .merge(print: ['300x300>', :JPG],
           medium: ['1024x1024>', :JPG],
           large: ['1920x1920>', :JPG],
           ultra: ['3840x3840>', :JPG],
           panorama_medium: ['1024x1024^', panorama_format],
           panorama_large: ['1920x1080^', panorama_format],
           panorama_mask: ['1920x1080^', panorama_format])
end
SOURCE_FILE_OPTIONS =
{
  # Prevent anti aliasing. Otherwise, when processing color map
  # images, borders between areas are blurred.
  panorama_mask: '-filter point'
}.freeze
CONVERT_OPTIONS =
{
  print: '-quality 10 -interlace Plane',
  medium: '-quality 70 -interlace Plane',
  large: '-quality 70 -interlace Plane',
  ultra: '-quality 90 -interlace Plane',
  panorama_medium: '-quality 70 -interlace Plane',
  panorama_large: '-quality 70 -interlace Plane',
  panorama_mask: "-quality 70 -interlace Plane -dither None -colors 64 -remap #{palette_path}"
}.freeze

Instance Method Summary collapse

Methods included from UploadedFile

#file_type, #nested_files, #parent_allows_type_for_nesting, #parent_belongs_to_same_entry

Methods included from ImageFileStateMachine

#publish!, #ready?, #retry!, #retryable?

Instance Method Details

#attachmentObject



53
54
55
# File 'app/models/pageflow/image_file.rb', line 53

def attachment
  processed_attachment.present? ? processed_attachment : unprocessed_attachment
end

#attachment=(value) ⇒ Object



57
58
59
# File 'app/models/pageflow/image_file.rb', line 57

def attachment=(value)
  self.unprocessed_attachment = value
end

#basenameObject



61
62
63
# File 'app/models/pageflow/image_file.rb', line 61

def basename
  File.basename(attachment.original_filename, '.*')
end

#original_urlObject



75
76
77
78
79
# File 'app/models/pageflow/image_file.rb', line 75

def original_url
  if processed_attachment.present?
    attachment.url
  end
end

#panorama_mask_urlObject



87
88
89
90
91
# File 'app/models/pageflow/image_file.rb', line 87

def panorama_mask_url
  if processed_attachment.present?
    attachment.url(:panorama_mask)
  end
end

#panorama_urlObject



81
82
83
84
85
# File 'app/models/pageflow/image_file.rb', line 81

def panorama_url
  if processed_attachment.present?
    attachment.url(:panorama_large)
  end
end

#thumbnail_url(*args) ⇒ Object



65
66
67
# File 'app/models/pageflow/image_file.rb', line 65

def thumbnail_url(*args)
  processed_attachment.url(*args)
end

#urlObject



69
70
71
72
73
# File 'app/models/pageflow/image_file.rb', line 69

def url
  if processed_attachment.present?
    attachment.url(:large)
  end
end