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.
Class Method Summary collapse
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
- #unzip_files ⇒ Object
Instance Attribute Details
#crop_h ⇒ Object
Returns the value of attribute crop_h.
28 29 30 |
# File 'app/models/goldencobra/upload.rb', line 28 def crop_h @crop_h end |
#crop_image ⇒ Object
Returns the value of attribute crop_image.
28 29 30 |
# File 'app/models/goldencobra/upload.rb', line 28 def crop_image @crop_image end |
#crop_w ⇒ Object
Returns the value of attribute crop_w.
28 29 30 |
# File 'app/models/goldencobra/upload.rb', line 28 def crop_w @crop_w end |
#crop_x ⇒ Object
Returns the value of attribute crop_x.
28 29 30 |
# File 'app/models/goldencobra/upload.rb', line 28 def crop_x @crop_x end |
#crop_y ⇒ Object
Returns the value of attribute crop_y.
28 29 30 |
# File 'app/models/goldencobra/upload.rb', line 28 def crop_y @crop_y end |
#image_url ⇒ Object
Returns the value of attribute image_url.
28 29 30 |
# File 'app/models/goldencobra/upload.rb', line 28 def image_url @image_url end |
Class Method Details
.default_position ⇒ Object
139 140 141 142 |
# File 'app/models/goldencobra/upload.rb', line 139 def self.default_position Goldencobra::Setting.for_key("goldencobra.article.image_positions"). to_s.split(",").map(&:strip).first end |
Instance Method Details
#complete_list_name ⇒ Object
94 95 96 97 98 99 |
# File 'app/models/goldencobra/upload.rb', line 94 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")}" end |
#crop_image_with_coords ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/goldencobra/upload.rb', line 70 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
131 132 133 134 135 136 137 |
# File 'app/models/goldencobra/upload.rb', line 131 def image_file? if !(self.image_content_type =~ /^image.*/).nil? || !(self.image_content_type =~ /pdf/).nil? true else false end end |
#title ⇒ Object
90 91 92 |
# File 'app/models/goldencobra/upload.rb', line 90 def title "#{self.image_file_name} (#{self.image_content_type})" end |
#unzip_files ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/goldencobra/upload.rb', line 101 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) zipped_files.each do |zipped_file| filename = zipped_file.name.split("/").last.gsub(" ", "_").gsub(/[^0-9A-z.\-]/, "") file_path = "tmp/#{self.id}_#{filename}" next if filename[0] == "." if zipped_file.file? zipped_file.extract(file_path) Goldencobra::Upload.create( image: File.open(file_path), image_file_name: filename, source: self.source, rights: self.rights, description: self.description, tag_list: self.tag_list.join(", ") ) File.delete(file_path) end end end end |