2018-06-05, 05:49 AM
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).
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);
}