Class: Goldencobra::Upload
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Goldencobra::Upload
- Defined in:
- app/models/goldencobra/upload.rb
Instance Attribute Summary collapse
-
#crop_h ⇒ Object
Returns the value of attribute crop_h.
-
#crop_image ⇒ Object
Returns the value of attribute crop_image.
-
#crop_w ⇒ Object
Returns the value of attribute crop_w.
-
#crop_x ⇒ Object
Returns the value of attribute crop_x.
-
#crop_y ⇒ Object
Returns the value of attribute crop_y.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
Instance Method Summary collapse
- #complete_list_name ⇒ Object
- #crop_image_with_coords ⇒ Object
-
#image_file? ⇒ Boolean
Internal: Makes sure to only post-process files which are either pdf or image files.
-
#title ⇒ Object
def crop_image_with_coords if self.crop_image.present? && self.crop_image == “1” && self.crop_x.present? && self.crop_y.present? && self.crop_w.present? && self.crop_h.present? && self.crop_image.present? orig_img = Magick::ImageList.new(self.image.path(:original)) orig_img.crop(self.crop_x.to_i, self.crop_y.to_i, self.crop_w.to_i, self.crop_h.to_i) orig_img.write(self.image.path(:original)) #self.image = File.open(“tmp/cropped_image”) #self.image.reprocess! end end.
- #unzip_files ⇒ Object
Instance Attribute Details
#crop_h ⇒ Object
Returns the value of attribute crop_h.
25 26 27 |
# File 'app/models/goldencobra/upload.rb', line 25 def crop_h @crop_h end |
#crop_image ⇒ Object
Returns the value of attribute crop_image.
25 26 27 |
# File 'app/models/goldencobra/upload.rb', line 25 def crop_image @crop_image end |
#crop_w ⇒ Object
Returns the value of attribute crop_w.
25 26 27 |
# File 'app/models/goldencobra/upload.rb', line 25 def crop_w @crop_w end |
#crop_x ⇒ Object
Returns the value of attribute crop_x.
25 26 27 |
# File 'app/models/goldencobra/upload.rb', line 25 def crop_x @crop_x end |
#crop_y ⇒ Object
Returns the value of attribute crop_y.
25 26 27 |
# File 'app/models/goldencobra/upload.rb', line 25 def crop_y @crop_y end |
#image_url ⇒ Object
Returns the value of attribute image_url.
25 26 27 |
# File 'app/models/goldencobra/upload.rb', line 25 def image_url @image_url end |
Instance Method Details
#complete_list_name ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/models/goldencobra/upload.rb', line 82 def complete_list_name result = "" result << "#{self.image_file_name} " if self.image_file_name.present? result << "(#{self.source}, #{self.rights}) " if self.source.present? || self.rights.present? result << "- #{self.updated_at.strftime("%d.%m.%Y - %H:%M Uhr")}" return result end |
#crop_image_with_coords ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/goldencobra/upload.rb', line 46 def crop_image_with_coords require 'RMagick' # Should we crop? if self.crop_image.present? && self.crop_image == "1" && self.crop_x.present? && self.crop_y.present? && self.crop_w.present? && self.crop_h.present? scaled_img = Magick::ImageList.new(self.image.path(:large)) orig_img = Magick::ImageList.new(self.image.path(:original)) scale = orig_img.columns.to_f / scaled_img.columns args = [ self.crop_x.to_i, self.crop_y.to_i, self.crop_w.to_i, self.crop_h.to_i ] args = args.collect { |a| a.to_i * scale } orig_img.crop!(*args) orig_img.write(self.image.path(:original)) self.crop_image = false self.image.reprocess! end end |
#image_file? ⇒ Boolean
Internal: Makes sure to only post-process files which are either pdf or image files. Word documents would break file upload.
No params
Returns true for image or pdf files and false for everything else
116 117 118 119 120 121 122 123 124 125 |
# File 'app/models/goldencobra/upload.rb', line 116 def image_file? #debugger if !(self.image_content_type =~ /^image.*/).nil? return true elsif !(self.image_content_type =~ /pdf/).nil? return true else return false end end |
#title ⇒ Object
def crop_image_with_coords
if self.crop_image.present? && self.crop_image == "1" && self.crop_x.present? && self.crop_y.present? && self.crop_w.present? && self.crop_h.present? && self.crop_image.present?
orig_img = Magick::ImageList.new(self.image.path(:original))
orig_img.crop(self.crop_x.to_i, self.crop_y.to_i, self.crop_w.to_i, self.crop_h.to_i)
orig_img.write(self.image.path(:original))
#self.image = File.open("tmp/cropped_image")
#self.image.reprocess!
end
end
76 77 78 |
# File 'app/models/goldencobra/upload.rb', line 76 def title "#{self.image_file_name} (#{self.image_content_type})" end |
#unzip_files ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/goldencobra/upload.rb', line 90 def unzip_files if self.image_file_name.include?(".zip") && File.exists?(self.image.path) require 'zip' zipped_files = Zip::File.open(self.image.path) int = 0 zipped_files.each do |zipped_file| int = int + 1 if zipped_file.file? zipped_file.extract("tmp/#{self.id}_unzipped_#{int}.jpg") Goldencobra::Upload.create(:image => File.open("tmp/#{self.id}_unzipped_#{int}.jpg"), :source => self.source, :rights => self.rights, :description => self.description, :tag_list => self.tag_list.join(", ") ) File.delete("tmp/#{self.id}_unzipped_#{int}.jpg") end end end end |