Hi Jonathan...
I haven(t tested so I can't be sure, but it seems to me that your problem comes from the fact that you are displaying the image first THEN download it. here's why:
- when you display an image, it comes on the users screen, which is in this case working at 96 dpi
- when you start the download, as the image is ALREADY loaded by the browser for display, the cache system makes it come from the browser (96 dpi), not a second time from your server (300 dpi)
so if I'm right, a solution would be to save the image twice and use a different image name for the download...
BUT, dpi is not all, in fact it's just an information in the image header, and the total number of pixels of your image should not be affected by this: if your image is 800x600 originally, it should still be 800x600 at the end, even if it's tag as 96 dpi.
in fact, I found out in my image processing code that ignoring the dpi is generally a good idea, and working based on the image size help a lot instead
Best regards