Sometimes I need a Lossless Screenshot Resizer Sometimes I need to write more documentation than just comments in code. And sometimes, those explanations need screenshots. Sometimes the conditions to get such a screenshot are so weird that I ask a developer to take a screenshot for me. Sometimes the screenshot does not fit my specifications and I have to resize it so that it looks nicely.

As you can see, the circumstances for a need for the magic "Lossless Screenshot Resizer" are very unlikely. Anyway, for me it seems I need it every day. But it doesn't exist yet.

I've seen you here on PCG solve awesome graphical puzzles before, so I guess this one is rather boring for you...

Specification


The program takes a screenshot of a single window as input
The screenshot does not make use of glass effects or similar (so you don't need to deal with any background stuff that shines through)
The input file format is PNG (or any other lossless format so that you don't have to deal with compression artifacts)
The output file format is the same as the input file format
The program creates a screenshot of different size as output. Minimum requirement is shrinking in size.
The user shall specify the expected output size. If you can give hints about the minimum size your program can produce from the given input, that's helpful.
The output screenshot must not have less information if interpreted by a human. You shall not remove text or image content, but you shall remove areas with background only. See examples below.
If it is not possible to get the expected size, the program should indicate that and not simply crash or remove information without further notice.
If the program indicates the areas which will be removed for verification reasons, that should increase its popularity.
The program may need some other user input, e.g. to identify the starting point for optimization.


Rules

This is a popularity contest. The answer with most votes on 2015-03-08 gets accepted.

Examples

Windows XP screenshot. Original size: 1003x685 pixels. 



Example areas (red: vertical, yellow: horizontal) that can be removed without losing any information (text or images). Note that the red bar isn't contiguous. This example doesn't indicate all possible pixels that could potentially be removed.



Losslessly resized: 783x424 pixels.



Windows 10 screenshot. Original size: 999x593 pixels.



Example areas which can be removed.



Losslessly resized screenshot: 689x320 pixels. 

Note that it is ok that the title text ("Downloads") and "This folder is empty" are not centered any more. Of course, it would be nicer if it is centered, and if your solution provides that, it should become more popular.
Python
the function delrows deletes all but one duplicate rows and returns the transposed image, applying it twice also deletes the columns and transposes it back. Additionally threshold controls how many pixels can differ for two lines to be still considered the same
from scipy import misc
from pylab import *

im7 = misc.imread('win7.png')
im8 = misc.imread('win8.png')

def delrows(im, threshold=0):
    d = diff(im, axis=0)
    mask = where(sum((d!=0), axis=(1,2))&gt;threshold)
    return transpose(im[mask], (1,0,2))
    
imsave('crop7.png', delrows(delrows(im7)))
imsave('crop8.png', delrows(delrows(im8)))



Flipping the comparator in mask from &gt; to &lt;= will instead output the removed areas which are mostly blank space.


golfed (because why not)
Instead of comparing each pixel it only looks at the sum, as a side effect this also converts the screenshot to greyscale and has trouble with sum-preserving permutations, like the down-arrow in the address bar of the Win8 screenshot
from scipy import misc
from pylab import*
f=lambda M:M[where(diff(sum(M,1)))].T
imsave('out.png', f(f(misc.imread('in.png',1))),cmap='gray')