Crop + Gravity + Paperclip

Ruby posted 9 months ago by christian

By default the cropping is weighted at the center of the Geometry. I want it to be north west, so I came up with this dirty hack for setting the gravity to north west:

   1  module Paperclip
   2   
   3     # Defines the geometry of an image.
   4    class Geometry
   5  
   6       def cropping dst, ratio, scale
   7         if ratio.horizontal? || ratio.square?
   8           #"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
   9           "%dx%d+%d+%d" % [ dst.width, dst.height, 0, 0 ]
  10         else
  11           #"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
  12           "%dx%d+%d+%d" % [ dst.width, dst.height, 0, 0 ]
  13         end
  14       end
  15    end
  16  end

Tagged paperclip, geometry, weight, center

Opening a new window in the center of the screen with JavaScript

JavaScript posted about 1 year ago by christian

This JavaScript code will open a URL in a new window and center the window on the screen, instead of showing the window in a random place:

   1  var url = 'http://google.com/';
   2  var width  = 640;
   3  var height = 480;
   4     
   5  var left   = (screen.width / 2) - (width / 2);
   6  var top    = (screen.height / 2) - (height / 2);
   7     
   8  var xWindow = window.open(url, 'post', 'resizable=1,width=' + width + ',height=' + height + ', top=' + top + ', left=' + left);
   9  
  10  xWindow.focus(); 

Tagged javascript, window, open, center, screen