Resize image attachments
#1
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).


                $toename = str_replace(".attach", "_small.$ext", $filename);
                $toepathname = $mybb->settings['uploadspath']."/".$toename;
                $filepathname = $mybb->settings['uploadspath']."/".$filename;
                $toenail = generate_thumbnail($filepathname, $mybb->settings['uploadspath'], $toename, 900, 900);
                if($toenail['filename'])
                {
                        if (!rename($toepathname, $filepathname))
                                unlink($toepathname);
                }
Reply


Messages In This Thread
Resize image attachments - by azalea4va - 2018-06-05, 05:49 AM
RE: Resize image attachments - by SvePu - 2018-06-05, 07:41 AM
RE: Resize image attachments - by Eldenroot - 2018-06-12, 07:33 PM
RE: Resize image attachments - by WallBB - 2018-06-13, 09:31 AM
RE: Resize image attachments - by PEpler - 2019-03-15, 01:30 PM
RE: Resize image attachments - by PEpler - 2020-07-21, 03:00 PM
RE: Resize image attachments - by Laird - 2020-07-22, 01:58 PM
RE: Resize image attachments - by gsujatha945 - 2019-07-24, 04:32 AM
RE: Resize image attachments - by Eldenroot - 2020-12-19, 09:08 PM
RE: Resize image attachments - by Laird - 2020-12-21, 01:45 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)