refactor attach image function
refactor attach image function