class Fdimage
Constants
- VERSION
Attributes
archivo[RW]
Solo funciona al subir una nueva imagen y solo desde la plataforma, no desde la app TODO:
Recortar archivos subidos
params[RW]
Solo funciona al subir una nueva imagen y solo desde la plataforma, no desde la app TODO:
Recortar archivos subidos
Public Class Methods
new(data, params: {})
click to toggle source
# File lib/fdimage.rb, line 13 def initialize(data, params: {}) self.archivo = Fdarchivo.new(data) self.params = params end
tmp_multi_upload(paths, owner = nil)
click to toggle source
# File lib/fdimage.rb, line 78 def self.tmp_multi_upload(paths, owner = nil) code = Fdarchivo.gen_upload_code paths.each do |path| a = self.new(path) a.fix_orientacion_apple a.archivo.tmp_upload(owner, code: code) end code end
tmp_upload(path, owner = nil)
click to toggle source
# File lib/fdimage.rb, line 87 def self.tmp_upload(path, owner = nil) code = Fdarchivo.gen_upload_code a = self.new(path) a.fix_orientacion_apple a.archivo.tmp_upload(owner, code: code) code end
upload(path, owner = nil)
click to toggle source
# File lib/fdimage.rb, line 95 def self.upload(path, owner = nil) code = Fdarchivo.gen_upload_code a = self.new(path) a.fix_orientacion_apple a.archivo.upload(owner, code: code) code end
Public Instance Methods
convert(parametros: self.params)
click to toggle source
# File lib/fdimage.rb, line 47 def convert(parametros: self.params) self.get_tmp_file if parametros MiniMagick::Tool::Convert.new do |c| c << "#{self.archivo.path}" if parametros[:rotate]!=0 c << '-rotate' << "#{parametros[:rotate].to_i}" end c << '-crop' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+#{parametros[:x].to_f}+#{parametros[:y].to_f}" if parametros[:x].to_f<0 && parametros[:y].to_f<0 c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+#{parametros[:x].to_f.abs}+#{parametros[:y].to_f.abs}" elsif parametros[:y].to_f<0 c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+0+#{parametros[:y].to_f.abs}" elsif parametros[:x].to_f<0 c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+#{parametros[:x].to_f.abs}+0" else c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+0+0" end c << '-format' << 'jpeg' c << '-background' << 'white' c << '-depth' << '8' c << '-density' << '72' c << '+channel' c << '-flatten' c << '-strip' c << '-gaussian-blur' << '0.05' c << self.archivo.path end end end
fix_orientacion_apple()
click to toggle source
# File lib/fdimage.rb, line 18 def fix_orientacion_apple exif = MiniMagick::Image.open(self.archivo.path).exif if exif['Orientation'] MiniMagick::Tool::Convert.new do |c| c << self.archivo.path case exif['Orientation'] when '6' c.rotate << '90' when '8' c.rotate << '-90' when '3' c.rotate << '180' end c << '-strip' c << self.archivo.path end end end
get_tmp_file()
click to toggle source
# File lib/fdimage.rb, line 37 def get_tmp_file new_path = "#{Rails.root}/public/tmp/" unless Dir.exist?(new_path) FileUtils.mkpath(new_path) end new_path << "#{self.archivo.archivo.original_filename}" FileUtils.mv(self.archivo.path, new_path) self.archivo.path = new_path end