dada-mail
dada-mail copied to clipboard
Resize attached images in discussion lists
People seem to LOVE sending enormous images through discussion lists, and this problem isn't going away; image sizes are just getting bigger and bigger.
Perhaps an option to resize images to realistic sizes. This would stop people getting messages rejected.
Another option is to change attachments to linked images, but I'm less hot on this idea, since Dada Mail does the opposite by default.
Imager looks like the way to go:
https://metacpan.org/pod/Imager
https://github.com/tonycoz/imager
Resize an image: https://metacpan.org/pod/distribution/Imager/lib/Imager/Transformations.pod#scale()
We can also just start off with jpegs to change the quality: https://metacpan.org/pod/distribution/Imager/lib/Imager/Files.pod#JPEG
I think I like the idea of doing both. Having a max width/height, and a compression pass. Both only for images that are over a certain size.
Image::Resize is already used in Dada Mail, so it could make sense just to reuse it for this application, to get things started. It doesn't support compression natively, but the GD object it returns does, so we might as well use that.
So, one step is to pull the resize code out of where it is now, and repurpose it. Good! Then, at the compression level to that code. Brilliant! Sure I can either pas the obj around, or the ref to the string that is the image.