Clase para las fotos de la fototeca
Para poder validar que al importar las fotos ponen un directorio sin espacios ni tildes
The aspect ratio of the dimensions.
# File app/models/photo.rb, line 130 def aspect width.to_f / height.to_f if !(width.blank? && height.blank?) end
Para poder reusar /documents/_share
# File app/models/photo.rb, line 86 def body "" end
# File app/models/photo.rb, line 49 def date date_time_original || created_at end
# File app/models/photo.rb, line 80 def draft? !published? end
Should try to use Paperclip::Geometry instead returns [width, height], if possible
# File app/models/photo.rb, line 92 def geometry_from_file file = Photo::PHOTOS_PATH + version(:original, :relative) geometry = begin Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"]) rescue => err logger.info "No he podido coger las dimensiones de #{self.id}: #{err}" "" end if match = (geometry.match(/\b(\d*)x?(\d*)\b([\>\<\#\@\%^!])?/)) match.to_a[1,2] else logger.info "No he podido coger las dimensiones de #{self.id}: #{geometry}" "" end # parse(geometry) || # raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command.")) end
True if the dimensions represent a horizontal rectangle
# File app/models/photo.rb, line 116 def horizontal? height < width if !(width.blank? && height.blank?) end
# File app/models/photo.rb, line 70 def is_public? true end
# File app/models/photo.rb, line 125 def orientation self.vertical? ? 'portrait' : 'landscape' end
Indica si la foto está publicada. Lo está si está en algún album publicado
# File app/models/photo.rb, line 75 def published? albums = self.albums albums.length > 0 && albums.collect(&:draft).include?(false) end
# File app/models/photo.rb, line 135 def set_geometry self.width, self.height = self.geometry_from_file end
True if the dimensions represent a square
# File app/models/photo.rb, line 111 def square? height == width if !(width.blank? && height.blank?) end
Devuelve la versión de tamaño size de la foto actual.
size:
tamaño deseado. Los valores permitidos son los keys de
Tools::Multimedia::PHOTOS_SIZES, definido en el módulo #PhotoPaths
path:
no se usa
# File app/models/photo.rb, line 57 def version(size=:n70, path=:absolute) if Tools::Multimedia::PHOTOS_SIZES.keys.include?(size) version_path = "#{File.dirname(self.file_path)}/#{size}/#{File.basename(self.file_path)}" else version_path = self.file_path end if path.eql?(:absolute) return Photo::PHOTOS_URL + version_path else return version_path end end
True if the dimensions represent a vertical rectangle
# File app/models/photo.rb, line 121 def vertical? height > width if !(width.blank? && height.blank?) end