Class: Pageflow::ImageFile

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

Overview

rubocop:todo Style/Documentation

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



75
76
77
78
79
80
81
82
83
84
# File 'app/models/pageflow/image_file.rb', line 75

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 ->



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

def attachment_default_url
  ':pageflow_placeholder'
end

#attachment_styles(attachment) ⇒ Object



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
63
64
65
66
67
68
# File 'app/models/pageflow/image_file.rb', line 38

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'
                              }
                            )
    .merge(social_image_styles)
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



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

def original_url
  attachment.url if ready?
end

#panorama_urlObject



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

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

#thumbnail_urlObject



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

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

  attachment.url(*)
end

#urlObject



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

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