made image resizing safer