Bugfix

$path was being used instead of $filename.
Incorrect scaling was being applied, we now first scale the image if
greater than max_width, then rescale it form HD to SD if needed to keep
proportions.