Dynamically calculate padding-left

Hi,

Here’s a sample division:

<div style="padding:0 0 0 40px; background:url(comment-icon.png) left center no-repeat;">some text</div>

I wonder how I can calculate the padding-left:40px dynamically so that any icon I choose the padding-left value changes according to the image width.

Any help is appreciated!

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.