detect image width/height, convert error messages to right mime-type, php 5.1- compat