Class: MiniMagick::Image

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/manage/cms_pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#crop_resized(ncols, nrows, gravity = 'Center') ⇒ Object



1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
# File 'app/controllers/manage/cms_pages_controller.rb', line 1508

def crop_resized(ncols, nrows, gravity='Center')
  columns = self[:width].to_i
  rows = self[:height].to_i
  
  if ncols != columns || nrows != rows
    scale = [ncols/columns.to_f, nrows/rows.to_f].max
    resize("#{scale*(columns+0.5).to_i}x#{scale*(rows+0.5).to_i}")
  end
  
  columns = self[:width].to_i
  rows = self[:height].to_i
  crop("#{ncols}x#{nrows}+0+0", "-gravity", "#{gravity}") if ncols != columns || nrows != rows
end