measure image size using pure Ruby (by Keisuke Minami)