To do this client-side with JS, you'd need to:
a) Read the background image
b) Insert it into the page (use absolute positioning to move it off the top-left)
c) Get the width of the visible image
d) Update the padding of original element with new value
e) Remove image from page
To do it server-side, you could probably use a PHP image library.