you dont need any js for this
this is pretty simple
*note that this will work with img like object which have height and width fixed but not know to us and for text u need to use js to run it cross browser correctly
have a look to this fiddle http://jsfiddle.net/Ukvfw/
and with smaller image same code http://jsfiddle.net/Ukvfw/1/
here is the code
html - (you can change the image link and try with any height and width)
<div class="parent">
<img class="child" src="http://wiki.guildwars.com/images/thumb/6/60/User_Jette_awesome.svg/2048px-User_Jette_awesome.svg.png" />
</div>
css -
.parent{
width:300px;
height:300px;
position:relative;
border:1px solid red;
padding:10px;
}
.child{
position: absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto;
max-height:300px;
max-width:300px;
}