You call it Centering, I call it Code Golf "Let's face it, aligned images are like little gifts from Heaven. Welcome, but unexpected." - Geobits

+10000 reputation to whoever wins this challenge.

Rules:

1) You are to generate a program.

2) Input will be an image, however whether it is passed as a file or a list of numbers is up to you.

3) Output will be a file which when opened in paint (or similar) will show the image aligned.

4) The canvas size will always be between 100 x 100 and 2000 x 2000 pixels. It will always be a rectangle, but not always a square.

5) No hard coding of images or funky URL magic.

6) No external libraries to be used.

Guide to Centralisation (Joshpbarron Variant)

An image will be defined as centered if the 1st white(255,255,255,>0 rgba) or transparent(x,y,z,0 rgba) on an axis is equal distance (plus or minus 1 pixel) from the edge of the canvas.

This can be achieved (and will be verified by) the following method. 

1) Imagine a bounding box around the object. (Black lines added for help)



2) Move the object around until the edge of the object is equal distance from the appropriate edge of the canvas.



3) Now forget the black lines.



Input:



Output:



More inputs here.

And respective outputs here.

The +10000 rep is a lie.
HTML5 + JavaScript (ES5), 515 bytes

That count includes the HTML tags as they are part of the program. If you only count the image processing code, it is 376 bytes including the function wrapper.

&lt;canvas id=o&gt;&lt;/canvas&gt;&lt;script&gt;f=function(p){o=new Image();o.crossOrigin='Anonymous';o.src=p;o.onload=function(){v=document.getElementById('o'),c=v.getContext('2d');v.width=l=w=o.width;v.height=t=h=o.height;c.drawImage(o,0,0);for(k=255,d=c[g='getImageData'](0,0,w,h).data,r=b=i=0;i&lt;d.length;)if((d[i++]&lt;k||d[i++]&lt;k||d[i++]&lt;k)&amp;&amp;d[i++]){x=i/4%w;y=~~(i/4/w);l=l&lt;x?l:x;t=t&lt;y?t:y;b=b&gt;y?b:y;r=r&gt;x?r:x}n=c[g](l,t,r-l+1,b-t+1);c.clearRect(0,0,w,h);c.putImageData(n,(w-r+l)/2,(h-b+t)/2)}}&lt;/script&gt;&lt;input onblur=f(this.value)&gt;


Input

A URL to an image.

Security restrictions

Because this program is running in a browser environment, only URLs to CORS-enabled images will work. Imgur is CORS enabled.

IE 10 does not support CORS. I haven't tested in IE 11 yet but it does work in Chrome and Firefox.

How to run


Type/paste in a URL into the input field.
De-focus (tab/click out of) from the input field.


Output

It outputs on the canvas on the page.

As this is a browser-based application, security restrictions prevent automatic download of a file but you can right click and save image in Chrome and Firefox. I haven't tested on IE 11 yet.

Demo

JavaScript code has been removed from the script element and put into the appropriate area to accommodate Stack Snippets:



f = function(p) {
  o = new Image();
  o.crossOrigin = 'Anonymous';
  o.src = p;
  o.onload = function() {
    v = document.getElementById('o'), c = v.getContext('2d');
    v.width = l = w = o.width;
    v.height = t = h = o.height;
    c.drawImage(o, 0, 0);
    for (k = 255, d = c[g = 'getImageData'](0, 0, w, h).data, r = b = i = 0; i &lt; d.length;)
      if ((d[i++] &lt; k || d[i++] &lt; k || d[i++] &lt; k) &amp;&amp; d[i++]) {
        x = i / 4 % w;
        y = ~~(i / 4 / w);
        l = l &lt; x ? l : x;
        t = t &lt; y ? t : y;
        b = b &gt; y ? b : y;
        r = r &gt; x ? r : x
      }
    n = c[g](l, t, r - l + 1, b - t + 1);
    c.clearRect(0, 0, w, h);
    c.putImageData(n, (w - r + l) / 2, (h - b + t) / 2)
  }
}
&lt;canvas id=o&gt;&lt;/canvas&gt;
&lt;input onblur=f(this.value)&gt;