Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resize image attachments
I have seen a number of tools that talk of resizing images, but so far each of those tools was just resizing the display of the image, not the image file itself.  Cameras these days are creating images with a far higher resolution than is needed for the display of images attachments on my BB.  I would rather not waste the space of storing a 5184×2456 image when it is only going to be displayed at a resolution of 900x426.

Mybb already attempts to make a thumbnail file of an attachment, in "upload_attachment" in inc/functions_upload.php.  I modified this code to have it also create a second bigger thumbnail, what I will call a toenail, with max height and width of 900. After line 632, I added code to create the toenail file, and if successful, rename the toenail file to be the original downloaded attachment file.  It seems to work.  I am sharing what I have done here, asking if anyone has dealt with this themselves and if so, are there any "gotchas" that you can see in the code I have created.

The code added at the end of "upload_attachment (after line 632).

PHP Code:
               $toename str_replace(".attach""_small.$ext"$filename);
               $toepathname $mybb->settings['uploadspath']."/".$toename;
               $filepathname $mybb->settings['uploadspath']."/".$filename;
               $toenail generate_thumbnail($filepathname$mybb->settings['uploadspath'], $toename900900);
                       if (!rename($toepathname$filepathname))
Thx for's a nice function!

I did the same on another way and saved with it 80% of server storage space.

btw: this should be a core function Wink
Greetings Sven (ps: Sorry for my bad english!!)

My plugins - [email protected]
This is a great idea for plugin Wink
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Wow, very nice work Smile
I agree with @SvePu, this should be a core function.

Forum Jump:

Users browsing this thread: 1 Guest(s)