Optimize gif generating procedure.