Class: Pageflow::ImageFile

Inherits:
ActiveRecord::Base
  • Object
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])
end
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'
}.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



41
42
43
# File 'app/models/pageflow/image_file.rb', line 41

def attachment
  processed_attachment.present? ? processed_attachment : unprocessed_attachment
end

#attachment=(value) ⇒ Object



45
46
47
# File 'app/models/pageflow/image_file.rb', line 45

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

#basenameObject



49
50
51
# File 'app/models/pageflow/image_file.rb', line 49

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

#original_urlObject



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

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

#panorama_urlObject



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

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

#thumbnail_url(*args) ⇒ Object



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

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

#urlObject



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

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