Class: Image::Base
- Inherits:
-
Kuppayam::ApplicationRecord
- Object
- Kuppayam::ApplicationRecord
- Image::Base
show all
- Defined in:
- app/models/image/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#crop_h ⇒ Object
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_w ⇒ Object
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_x ⇒ Object
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_y ⇒ Object
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_configuration ⇒ Object
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_size ⇒ Object
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_image ⇒ Object
29
30
31
|
# File 'app/models/image/base.rb', line 29
def crop_image
image.recreate_versions! if crop_x.present?
end
|
#display_name ⇒ Object
44
45
46
|
# File 'app/models/image/base.rb', line 44
def display_name
"#{id} - #{self.class.name.split('::').last.titleize}"
end
|
#get_image_configuration ⇒ Object
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_limit ⇒ Object
80
81
82
|
# File 'app/models/image/base.rb', line 80
def max_upload_limit
get_image_configuration[:max_upload_limit]
end
|
#min_upload_limit ⇒ Object
84
85
86
|
# File 'app/models/image/base.rb', line 84
def min_upload_limit
get_image_configuration[:min_upload_limit]
end
|