Fixed a bug in the image packing code