I found this when looking for a solution to a similar problem, the solution uses CSS3, so it will not work on IE8 and below.
Although this is an old question, I decided that an updated answer might be useful to someone:
<div id="wrapper">
<div id="parent">
<img src="path/i/got/from/database/image.png">
</div>
</div>
#parent{
width:400px;
height:400px;
background:red; /* just used to highlight box */
text-align:center;
}
#parent img{
position:relative;
top: 50%;
transform: translateY(-50%);
}
See this script: http://jsfiddle.net/E9sTk/
source
share