Issue/950 image resize

Fix #950 - Rewrote picture resizing to be more memory-efficient, added better creation/deletion of temporary files, made minor changes based on code analysis