use nokogiri

Just some of my suggested changes.

I would highly recommend saving the image to a temp location where it can remain and be overwritten when a new file is downloaded. Also I did not find the resetting to be necessary.