Fix caching issue while image transformation

* Removed tempfile dependency.
* Fixed caching issue with images.
* Added test for the same.
* Re-factored test.