Class: Gluttonberg::Library::Processor::Image
- Inherits:
-
Object
- Object
- Gluttonberg::Library::Processor::Image
- Defined in:
- lib/gluttonberg/library/processor/image.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
Returns the value of attribute asset.
-
#replace_backup ⇒ Object
Returns the value of attribute replace_backup.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_cropped_image(x, y, w, h, image_type) ⇒ Object
-
#generate_image_thumbnails ⇒ Object
Create thumbnailed versions of image attachements.
- #generate_proper_resolution ⇒ Object
-
#generate_thumb_and_proper_resolution ⇒ Object
Generates thumbnails for images, but also additionally checks to see if the uploaded image exceeds the specified maximum, in which case it will resize it down.
- #suggested_measures(object, required_geometry) ⇒ Object
Instance Attribute Details
#asset ⇒ Object
Returns the value of attribute asset.
6 7 8 |
# File 'lib/gluttonberg/library/processor/image.rb', line 6 def asset @asset end |
#replace_backup ⇒ Object
Returns the value of attribute replace_backup.
6 7 8 |
# File 'lib/gluttonberg/library/processor/image.rb', line 6 def replace_backup @replace_backup end |
Class Method Details
.process(asset_obj, replace_backup = true) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/gluttonberg/library/processor/image.rb', line 8 def self.process(asset_obj, replace_backup=true) if asset_obj.asset_type.asset_category.name == "image" processor = self.new processor.asset = asset_obj processor.replace_backup = replace_backup processor.generate_thumb_and_proper_resolution end end |
Instance Method Details
#generate_cropped_image(x, y, w, h, image_type) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gluttonberg/library/processor/image.rb', line 57 def generate_cropped_image(x , y , w , h, image_type) asset_thumb = asset.asset_thumbnails.find_or_initialize_by_thumbnail_type(image_type.to_s) asset_thumb.user_generated = true asset_thumb.save config = asset.class.sizes[image_type.to_sym] file_name = "#{config[:filename]}.#{asset.file_extension}" image = read_image_file(asset) aurgments_str = _prepare_image_crop_arguments(x , y , w , h, config) _resize_and_save(asset, image, nil, aurgments_str, file_name) end |
#generate_image_thumbnails ⇒ Object
Create thumbnailed versions of image attachements.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gluttonberg/library/processor/image.rb', line 69 def generate_image_thumbnails asset.class.sizes.each_pair do |name, config| asset_thumb = asset.asset_thumbnails.where({ :thumbnail_type => name.to_s, :user_generated => true }).first _generate_image_thumbnail(name, config) if asset_thumb.blank? end # sizes loop asset.update_attribute(:custom_thumbnail , true) end |
#generate_proper_resolution ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/gluttonberg/library/processor/image.rb', line 83 def generate_proper_resolution asset.make_backup(replace_backup) image = read_image_file(asset) asset.update_attributes( :width => image.width.to_i, :height => image.height.to_i) _resize_and_save(asset, image, asset.class.max_image_size, nil, asset.file_name) clean_audio_attributes_for_images(asset) end |
#generate_thumb_and_proper_resolution ⇒ Object
Generates thumbnails for images, but also additionally checks to see if the uploaded image exceeds the specified maximum, in which case it will resize it down.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gluttonberg/library/processor/image.rb', line 19 def generate_thumb_and_proper_resolution begin if File.exist?(asset.tmp_location_on_disk) generate_proper_resolution generate_image_thumbnails end rescue => e puts e end end |
#suggested_measures(object, required_geometry) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gluttonberg/library/processor/image.rb', line 30 def suggested_measures(object , required_geometry) required_geometry_tokens = required_geometry.delete("#").split("x") actual_width = object.width.to_i actual_height = object.height.to_i required_width = required_geometry_tokens.first.to_i required_height = required_geometry_tokens.last.to_i ratio_required = required_width.to_f / required_height ratio_actual = actual_width.to_f / actual_height crossover_ratio = required_height.to_f / actual_height crossover_ratio2 = required_width.to_f / actual_width if(crossover_ratio < crossover_ratio2 ) crossover_ratio = crossover_ratio2 end projected_height = actual_height * crossover_ratio if(projected_height < required_height ) required_width = required_width * (1 + (ratio_actual - ratio_required ) ) end projected_width = actual_width * crossover_ratio "#{(projected_width).ceil}x#{(projected_width/ratio_actual).ceil}" end |