Class: Pageflow::ImageFile

Inherits:
ApplicationRecord show all
Includes:
ImageAndTextTrackProcessingStateMachine, OutputSource, UploadableFile
Defined in:
app/models/pageflow/image_file.rb

Constant Summary

Constants included from OutputSource

OutputSource::STATE_MAPPING

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OutputSource

#externally_generated_outputs, #output_presences, #output_presences=, #output_present?, #present_outputs

Methods included from ImageAndTextTrackProcessingStateMachine

#failed?, #ready?, #retry!, #retryable?

Methods included from UploadableFile

#attachment, #attachment=, #attachments_for_export, #basename, #can_upload?, #direct_upload_config, #extension, #failed?, #file_name, #publish!, #ready?, #retryable?

Methods included from ReusableFile

#attachments_for_export, #basename, #cache_key, #can_upload?, #extension, #failed?, #file_name, #file_type, #nested_files, #parent_allows_type_for_nesting, #parent_belongs_to_same_entry, #publish!, #ready?, #retry!, #retryable?

Class Method Details

.scale_down_to_cover(width, height) ⇒ Object

<- UploadableFile-overrides



69
70
71
72
73
74
75
76
77
78
# File 'app/models/pageflow/image_file.rb', line 69

def self.scale_down_to_cover(width, height)
  lambda do |image_file|
    if image_file.width.present? && image_file.height.present? &&
       (image_file.width <= width || image_file.height <= height)
      '100%'
    else
      "#{width}x#{height}^"
    end
  end
end

Instance Method Details

#attachment_default_urlObject

UploadableFile-overrides ->



33
34
35
# File 'app/models/pageflow/image_file.rb', line 33

def attachment_default_url
  ':pageflow_placeholder'
end

#attachment_styles(attachment) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/pageflow/image_file.rb', line 37

def attachment_styles(attachment)
  panorama_format = File.extname(attachment.original_filename) == '.png' ? :PNG : :JPG

  Pageflow
    .config.thumbnail_styles.transform_values { |options| options.merge(style_defaults) }
    .merge(
      print: {geometry: '300x300>',
              **style_defaults,
              convert_options: '-quality 10 -interlace Plane'},
      medium: {geometry: '1024x1024>',
               **style_defaults,
               convert_options: '-quality 70 -interlace Plane'},
      large: {geometry: '1920x1920>',
              **style_defaults,
              convert_options: '-quality 70 -interlace Plane'},
      ultra: {geometry: '3840x3840>',
              **style_defaults,
              convert_options: '-quality 90 -interlace Plane'},
      panorama_medium: {geometry: ImageFile.scale_down_to_cover(1024, 1024),
                        format: panorama_format,
                        convert_options: '-quality 90 -interlace Plane'},
      panorama_large: {geometry: ImageFile.scale_down_to_cover(1920, 1080),
                       format: panorama_format,
                       convert_options: '-quality 90 -interlace Plane'}
    )
end

#attachments_path_nameObject

used in paperclip initializer to interpolate the storage path needs to be “processed_attachments” for images for legacy reasons



11
12
13
# File 'app/models/pageflow/image_file.rb', line 11

def attachments_path_name
  'processed_attachments'
end

#original_urlObject



24
25
26
# File 'app/models/pageflow/image_file.rb', line 24

def original_url
  attachment.url if ready?
end

#panorama_urlObject



28
29
30
# File 'app/models/pageflow/image_file.rb', line 28

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

#thumbnail_url(*args) ⇒ Object



17
18
19
20
21
22
# File 'app/models/pageflow/image_file.rb', line 17

def thumbnail_url(*args)
  unless ready?
    return Pageflow::PaperclipInterpolations::Support.pageflow_placeholder(attachment, *args)
  end
  attachment.url(*args)
end

#urlObject



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

def url
  attachment.url(:large) if ready?
end