Compact array before converting to image