class ElFinder2::Command::Resize
Public Instance Methods
execute()
click to toggle source
# File lib/el_finder2/command/file.rb, line 4 def execute source = Paperclip.io_adapters.for(@file.content) dest = Paperclip::TempfileFactory.new.generate(source.path) Paperclip::Processor.new(source.path). convert(@convert_params, source: source.path, dest: dest.path) geometry = Paperclip::Geometry.from_file(dest.path) @file.content = dest @file.dimensions = "#{geometry.width.to_i}x#{geometry.height.to_i}" @file.save render json: { changed: ActiveModel::ArraySerializer.new([@file]).as_json } end
Private Instance Methods
for_crop(params)
click to toggle source
# File lib/el_finder2/command/file.rb, line 42 def for_crop(params) width, height, x, y = params.values_at(:width, :height, :x, :y) "-crop #{width}x#{height}+#{x}+#{y} :source :dest" if width && height && x && y end
for_resize(params)
click to toggle source
# File lib/el_finder2/command/file.rb, line 54 def for_resize(params) width, height = params.values_at(:width, :height) "-resize #{width}x#{height}! :source :dest" if width && height end
for_rotate(params)
click to toggle source
# File lib/el_finder2/command/file.rb, line 48 def for_rotate(params) degrees = params[:degree] "-rotate #{degrees} :source :dest" if degrees end
parse_params!(params)
click to toggle source
# File lib/el_finder2/command/file.rb, line 22 def parse_params!(params) target, mode = params.values_at(:target, :mode) fail ElFinder2::Error.new(%w(errCmdParams resize)) unless target && mode path = to_path(target) @file = ElFinder2::Image.find_by_path(path) fail ElFinder2::Error.new('errFileNotFound') unless @file @convert_params = case mode when 'crop' then for_crop(params) when 'resize' then for_resize(params) when 'rotate' then for_rotate(params) end fail ElFinder2::Error.new(%w(errCmdParams resize)) unless @convert_params end