Option to convert PNG to JPG on upload (because of phone uploads and Chrome copy/paste)

PlayerOne

Active member
I'd really love an option to automatically convert PNG to JPG on upload. A lot of our users, instead of using the image button on the edit bar and uploading a file, are clicking on a file, loading it in Chrome or IE, etc, clicking <right-click>,<copy> in the browser on Windows for example, (which loads the image basically as a png bitmap), and then hitting ctrl-v (paste) in the xenforo editor and uploading the file. So a 700k jpg becomes 6MB PNG. The same problem occurs when people upload with many types of phones...

Even better yet, it would be nice if there was a second option to set the min width or height to do such automatic conversion. I really don't care about PNGs less than 300 pixels wide or high for example, which might have a valid reason to be in a PNG format. This second option is much less important though.

Another idea is to allow independent resizing quality or dimensions for such a feature between regular posts and the media gallery.

While I'd prefer losing terrabytes of space unnecessarily, a larger concern here is both useful experience (time to load), and SEO (Google seem to like slow pages).

A similar suggestion was made over a year ago (in closed). I hope now it has more interest in day and age where more and more people are uploading with their phones, etc.
 
Upvote 12

Note that although the download notice says $35 that price is for all of @AndyB's. If you purchase the subscription, you have access to any or all of approximately 300 addons.
 
Thanks. I have his addons, but they don't seem to solve this problem. They allow one to convert an image manually. What I'm looking for is something that converts all PNGs (attached or pasted in the editor), automatically, at time of message save.

If you agree, please upvote (click up arrow at top right) this thread...
 
I have this issue as well and I use that addon. I would ping Andy and see if he is interested in developing something for this. Eventually I would love to convert all images to webp automatically but for now jpg it is...

The only problem would be transparent pngs...
 
I like this idea, never thought users would upload PNG photos ...

I've attached a little Add-on that should do this - it does convert PNG images to JPEG if they are larger than the maximum allowed attachment filesize.

Please note that transparency will be lost in this case.
I did implement code to detect transparency and ignore the file if it does contain transparency, but that quite simply does not make much sense to me so the code to do this is commented out:
If the image filesize is larger than allowed maximum and it is not being converted to JPEG, the upload would fail.
 

Attachments

PNGs are an issue because smartphones save screenshots in PNGs. Desktop OS also seems to save PNGs for screenshots. This is where most of the PNGs come from. My forum is tech based so a lot of users share screenshots showcasing the problems.

Also, from my understanding, XenForo also resize dimensions of the file (to set limits) before comparing file size with maximum limit set on the board. I wonder which one would be hit first after enabling your add-on?

Also, since you have programmed this to only convert is file size is larger than maximum allowed, I would need to reduce max file size supported on my board from 1 MB to 0.5 MB, otherwise it would probably never be used!

Thanks for this!
 
PNGs are an issue because smartphones save screenshots in PNGs. Desktop OS also seems to save PNGs for screenshots. This is where most of the PNGs come from. My forum is tech based so a lot of users share screenshots showcasing the problems.
Screenshots are usually a good candiate for PNG - large areas filled with the same color, you probably wouldn't gain that much by converting them to JPEG (but get artifacts).

Also, from my understanding, XenForo also resize dimensions of the file (to set limits) before comparing file size with maximum limit set on the board. I wonder which one would be hit first after enabling your add-on?
If the dimensions oa a PNG are larger than allowed XenForo would resize the file, if the filesize after resize is still more than allowed it would be converted to JPEG, if the filesize would still be too large it would be rejected.

Also, since you have programmed this to only convert is file size is larger than maximum allowed, I would need to reduce max file size supported on my board from 1 MB to 0.5 MB, otherwise it would probably never be used!
Yes, that was the idea - set the max. filesize to a value you want to allow.
I thought this was the easiest approach, but adding an independent setting would be easy as well.
 
Tried uploading a bunch of PNGs but never was able to hit the add-on. On most files, XenForo showed up a weird error saying file size is >5MB. 5MB is not the limit set for attachments! With this addon disabled, the same files uploaded just fine as they were under set limit after dimensions were resized. Even uploaded a PNG that matched the dimensions but was larger than configured file size and even that failed with this addon enabled somehow!
 
That's strange, works fine for me :)

First thing to check would be the exact error message and where the 5 MB message is coming from.
Do you have other class extensions on XF\Http\Upload?
 
The phrase is uploaded_file_is_too_large. Not sure how to check if this is from another add-on 🤔

Send me the file that works for you along with configured settings for dimension and file size to verify :D
 
Hey if you do decide to release it officially through resource manager, do consider providing an option for converting all PNGs to JPGs! I have this add-on enabled on my board for a few days now though I have no idea if it has been used since then :D Thanks!
 
I just tried this add on and had some issues... more detail over in the resource discussion. Look there for follow ups.
 
I'd get an add-on if it also converted GIFs to JPG. We don't allow animated GIFs on our sites (too distracting), so this would be a good way to get around members who try to slip one past the staff.
 
We've had some members try to sneak in animated GIF files as avatars, and at least when viewing their profile, the animation works. But that is outside the attachment system, so an add-on won't do much to help with that.
 
Top Bottom