[Split]Compressing uploaded image attachments?

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Anti-Spam Guide
digitaltoast
Registered User
Posts: 105
Joined: Thu Oct 18, 2007 9:33 am

[Split]Compressing uploaded image attachments?

Post by digitaltoast »

Well, that's a dead link now. I've been looking for the same.
Our "files" folder is now +4GB and most are images. I can very easily run a script to convert them all to webp and shrink the directory by at least 60% while keeping them looking the same, but how do I update the db with the new sizes etc?
Last edited by thecoalman on Tue Jan 09, 2024 9:45 am, edited 1 time in total.
Reason: Split to it's own topic from here: https://www.phpbb.com/community/viewtopic.php?t=1802695
Holger
Registered User
Posts: 1895
Joined: Tue Mar 12, 2002 3:54 pm
Location: Hannover

Re: Compressing uploaded image attachments?

Post by Holger »

4GB? Well thats cute ;) (sorry!)
I have 240GB in the userpix-folder (images only) and 17GB in the files-folder (mostly images).

Are you sure you need to reduce the size?
digitaltoast
Registered User
Posts: 105
Joined: Thu Oct 18, 2007 9:33 am

Re: Compressing uploaded image attachments?

Post by digitaltoast »

Yes, otherwise I wouldn't have asked.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6516
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: [Split]Compressing uploaded image attachments?

Post by thecoalman »

You can reduce file sizes by adding max dimensions. plupload will resize the file client side to max dimesnions. There is also a quality setting but this only applies to .jpg. Max dimensions set at 2000*2000 and 85% will give you file sizes around 500KB but will vary depending on the image content. Setting it at 1500*1500 will halve that. One thing to bear in mind is images smaller than max dimensions are not resized and may actually be larger file sizes since the compression settings on cameras is very light to nothing. .png uses lossless compression and and are going to be considerably larger than .jpg.

To use WebP It appears you would first have to add Webp to the images group under manage attachment extensions if it has not already been added.

The file size stored in the DB is not the only thing, you would also need to alter the extension stored in the database and possibly other things. This would require a custom script. If you are going to go that route I'd suggest handling both the conversion of the physical file and updating the DB in one script.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
MestresHackers
Registered User
Posts: 10
Joined: Mon Jan 21, 2008 10:47 pm
Name: Thalles Lázaro

Re: [Split]Compressing uploaded image attachments?

Post by MestresHackers »

digitaltoast wrote: Tue Jan 09, 2024 8:09 am Well, that's a dead link now. I've been looking for the same.
Our "files" folder is now +4GB and most are images. I can very easily run a script to convert them all to webp and shrink the directory by at least 60% while keeping them looking the same, but how do I update the db with the new sizes etc?
This would be greatly appreciated by many users, I think. The webp format is already on many sites by default. WordPress itself, with its domain i0.wp.com, does it for free.

Look at the difference in practice.

This is an original example image with 224kb (a white image with text)
https://thall.es/test.png

Now look at it converted to webp https://i0.wp.com/thall.es/test.png 61kb in webp format

This would be great in the optional core for those who want it. It would save a lot of storage, which I think not everyone has unlimited, and it would also improve the page loading speed a lot.

In practice, in PHP, to implement it:

Example of the code

Code: Select all

imagepalettetotruecolor($img);
imagealphablending($img, true);
imagesavealpha($img, true);
imagewebp($img, $dir . $newName, 80); <-- Image quality from 0 to 100 with 100 being the best quality
Only GIF images would not be compatible with this conversion because they would be static, but just ignore them and not Convert.

Come on PHPBB team, support the idea 😁
User avatar
nou nou
Registered User
Posts: 725
Joined: Sat Oct 29, 2016 8:08 pm

Re: [Split]Compressing uploaded image attachments?

Post by nou nou »

Return to “phpBB Discussion”