Pop-up window thats custom fitted for each image

I was wondering how you can make a pop up window the custom fit for various images.

PS. I’m a newbie at scripting.