Class: Image::Base

Inherits:
Kuppayam::ApplicationRecord
  • Object
show all
Defined in:
app/models/image/base.rb

Direct Known Subclasses

CoverImage, GalleryImage, LogoImage, ProfileImage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#crop_hObject

Returns the value of attribute crop_h.



8
9
10
# File 'app/models/image/base.rb', line 8

def crop_h
  @crop_h
end

#crop_wObject

Returns the value of attribute crop_w.



8
9
10
# File 'app/models/image/base.rb', line 8

def crop_w
  @crop_w
end

#crop_xObject

Returns the value of attribute crop_x.



8
9
10
# File 'app/models/image/base.rb', line 8

def crop_x
  @crop_x
end

#crop_yObject

Returns the value of attribute crop_y.



8
9
10
# File 'app/models/image/base.rb', line 8

def crop_y
  @crop_y
end

Class Method Details

.image_configurationObject

Configuration



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/image/base.rb', line 50

def self.image_configuration
  {
    max_upload_limit: 10485760,
    min_upload_limit: 1,
    resolutions: [550, 275],
    form_upload_image_label: "Upload a new Image",
    form_title: "Upload an Image",
    form_sub_title: "Please read the instructions below:",
    form_instructions: [
      "the filename should be in .jpg / .jpeg or .png format",
      "the image resolutions should be <strong>550 x 275 Pixels</strong>",
      "the file size should be greater than 100 Kb and or lesser than <strong>10 MB</strong>",
      "Note: most cameras and camera phones will produce images bigger than this"
    ]
   }
end

Instance Method Details

#check_file_sizeObject



33
34
35
36
37
38
39
40
41
42
# File 'app/models/image/base.rb', line 33

def check_file_size
  if image && image.file 
    if self.max_upload_limit && image.file.size.to_f > self.max_upload_limit
      errors.add(:image, "You cannot upload an image greater than #{Filesize.from(self.max_upload_limit.to_s+ " b").pretty}")
    end
    if self.min_upload_limit && image.file.size.to_f < self.min_upload_limit
      errors.add(:image, "You cannot upload an image lesser than #{Filesize.from(self.min_upload_limit.to_s+ " b").pretty}")
    end
  end
end

#crop_imageObject


Instance Methods



29
30
31
# File 'app/models/image/base.rb', line 29

def crop_image
  image.recreate_versions! if crop_x.present?
end

#display_nameObject



44
45
46
# File 'app/models/image/base.rb', line 44

def display_name
  "#{id} - #{self.class.name.split('::').last.titleize}"
end

#get_image_configurationObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/image/base.rb', line 67

def get_image_configuration
  imageable = self.imageable
  hsh = {}
  if imageable.respond_to?(:image_configuration) && imageable.image_configuration[self.image_type]
    hsh = imageable.image_configuration[self.image_type]
  elsif self.class.respond_to?(:image_configuration)
    hsh = self.class.image_configuration
  else
    hsh = Image::Base.image_configuration  
  end
  hsh.nil? ? {} : hsh
end

#max_upload_limitObject



80
81
82
# File 'app/models/image/base.rb', line 80

def max_upload_limit
  get_image_configuration[:max_upload_limit]
end

#min_upload_limitObject



84
85
86
# File 'app/models/image/base.rb', line 84

def min_upload_limit
  get_image_configuration[:min_upload_limit]
end