Attachment files - Can I resize them?

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Get Involved
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Pit$Bull
Former Team Member
Posts: 23099
Joined: Sat Dec 02, 2006 4:08 pm
Name: Can't Remember

Re: Attachment files - Can I resize them?

Post by Pit$Bull » Thu Apr 14, 2011 5:40 pm

I thought your issue was file size.
Resizing the image has nothing to do with filesize, it just renders it. The uploaded image stays the same.

carla1234
Registered User
Posts: 48
Joined: Mon Jan 24, 2011 7:01 pm

Re: Attachment files - Can I resize them?

Post by carla1234 » Thu Apr 14, 2011 5:54 pm

Pit$Bull wrote:I thought your issue was file size.
Resizing the image has nothing to do with filesize, it just renders it. The uploaded image stays the same.
So you tried this mod and its not working for you?

I installed the mod I tested it and it seems to work properly, I took my camera and set it on the highest setting which is 7 mega pixels then took a picture the picture ended up being 2.96 megs and a picture size of 3072 x 2304 when I upload the picture it ends up being 50.46 KiB and 800x600 when displayed, I cant verify if the 2.96 meg file is on my server I have 19,000 files in the "files" directory so all the last uploaded files down always show up when I look at them by FTP the only way I have found to view the files in the "files" directory is to download a back up from the server (over 5 gigs) then unzip it and look at the files.

So your telling me if I look in my "files" folder I will find a 2.96 meg file and a 50.46 kib file?

Pit$Bull
Former Team Member
Posts: 23099
Joined: Sat Dec 02, 2006 4:08 pm
Name: Can't Remember

Re: Attachment files - Can I resize them?

Post by Pit$Bull » Thu Apr 14, 2011 6:01 pm

Just the 2.96 meg file if that's what you uploaded.

User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50894
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Attachment files - Can I resize them?

Post by stevemaury » Thu Apr 14, 2011 6:01 pm

If you wish to find the encoded, extensionless file that corresponds to the file you uploaded, you can do it with this query ( Executing SQL Queries in phpMyAdmin KB ):

Code: Select all

SELECT physical_filename FROM phpbb_attachments WHERE real_filename = 'the name of the uploaded file.jpg';
You can then sort the FTP directory listing to make it easy to find the uploaded file and see how big it is. However, there is nothing in the code you posted that would change the size of the file sitting on the server. But check for yourself.
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

carla1234
Registered User
Posts: 48
Joined: Mon Jan 24, 2011 7:01 pm

Re: Attachment files - Can I resize them?

Post by carla1234 » Thu Apr 14, 2011 6:30 pm

Install it and try it please.

I just installed Uniserver http://www.uniformserver.com setup a local test server, installed our message board, tested it to verify it works, it did, added the modified code to the file then uploaded a 1.2 meg 2048x1536 picture it uploaded resized and I can only find a new 55k file in the "files" directory the date and time corresponds to the time I attached the file, I see no 1.2 meg file other than on my camera.

Next I need to fix the 2 meg limit and try larger files.

Unless I am missing something its working, working = its taking any pictures that are larger than 800x600 and resizing them to 800x600 then uploading them to the server, the original picture larger than 800x600 is NOT uploaded to the server and in the above example saving about 1.1 meg of space on the server.

Only tested with jpg files so far will have to test other formats later.

ALSO if I take the above 55k picture I used in the test above and add a extension .jpg to the end of the file I then can open the picture in my normal picture viewing program on my computer, this tells me I can take all the other multi meg pictures (gigs of them) already on our server download, do a batch rename adding the .jpg then resize them, then do another batch rename removing the .jpg extension then upload them to the server saving a few gigs of space on the server.

Looks like the unsolvable problems are about solved.

Thanks!

carla1234
Registered User
Posts: 48
Joined: Mon Jan 24, 2011 7:01 pm

Re: Attachment files - Can I resize them?

Post by carla1234 » Thu Apr 21, 2011 5:18 pm

Update

Despite what anybody has said here about this NOT WORKING it works for me on my site flawlessly.

Anybody else tried it, any problems?

Everybody is happy, no complaints the only error was when someone tried to upload a picture that was over 10 megs in size the picture size was like 4000 x 3000 this was when we were trying to test the limits of the system, he opened the file with a picture editor then saved it this reduced the file size to about 3 megs then it worked and resized the picture to 800x600 and about 100k file size no 3 meg+ file on the server taking up space for no good reason.

This mod is a great idea it helps update the capabilities and keeps up with digital camera evolution lets face it the picture sizes are only going to get BIGGER in the future so control over this needs to be in place, IMO the or change should be part of the standard phpbb3 features and configurable from the APC with the rest of the picture or attachment settings, if I had the slightest clue as how to do this I would write the mod and submit.

Resize pictures
Resize pictures on upload
Resize files
Resize files on upload

Thanks to everybody our site is now better and more functional than before we started to resolve this problem, no more over sized pictures and bloated file sizes to store on the server or archive in the backups, no more explaining to users why their pictures were rejected, no more explaining how to resize pictures, no more answering dumb emails, so far no complaints about their pictures being resized or no request for a larger version of the picture by others.

sbloomer
Registered User
Posts: 87
Joined: Fri Jun 12, 2009 8:18 pm

Re: Attachment files - Can I resize them?

Post by sbloomer » Wed Jul 06, 2011 8:47 am

I tried this mod... bar the fact that I translated the french to english :), but I am getting the following error, regardless of the image size I try upload

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19008 bytes) in xx/forum/includes/functions_upload.php on line 297.

Line 297 is this

Code: Select all

          if ( $this->extension == "jpg" || $this->extension == "jpeg" ) $source = imagecreatefromjpeg($this->destination_file);
My php.ini is set to 64MB, and the source file is 12MP 3.2MB file.

Any ideas?

EDIT: OK I the error was due to a misconfig, so I can now confirm this mod works as long as one sticks within the file limits imposed by one's server/host

sbloomer
Registered User
Posts: 87
Joined: Fri Jun 12, 2009 8:18 pm

Re: Attachment files - Can I resize them?

Post by sbloomer » Wed Jul 06, 2011 10:23 am

Having tested thus further, this mod didnt seem to honour the sizes as I would have expected, depending on whether the picture was landscape or portrait. With the width and height as set in the example a 1024x768 image would be correctly resized to 800x600, but a 768x1024 image would be resized to 448x600. this is fine for thumbnail generaiton behavior if you are stacking thumbnails above each other in a page, but is not quite the correct way to do it.

One would need to set the dimensions to the same value to display the correct behaviour

User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Attachment files - Can I resize them?

Post by 4_seven » Wed Jul 06, 2011 10:30 am

sorry for comment, but of course this script works
and of course it really reduces image-size + file-size.
Current Mods | Mod Base | php(BB) programming | No help via PM

User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Attachment files - Can I resize them?

Post by 4_seven » Wed Jul 06, 2011 10:35 am

sbloomer wrote:Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19008 bytes) in xx/forum/includes/functions_upload.php on line 297.
fine, that you have direct server access (and enough available ram) and have fixed that.

the others, without that comfort and enough (virtual) ram
and gets this error, can try the following:
ModX - Advanced Attach Watermark wrote:If u get a memory_limit error bcs. of to big pics (limits by server) try the following

Open

.htaccess

Enter at the begin:

php_value memory_limit 128M

This will work for pics ~ 3000 x 3000 px

or

php_value memory_limit 144M

This will work for pics ~ 4200 x 4200 px

Reduce or increase slowly in 4M Steps.

-----------

To check out how high u can go make a file memory.php

and load it up into forum root

Code: Select all

<?php
$y=ini_get('memory_limit');
echo $y;
?>
and call the file in browser.

> increase the .htaccess higher as this file displays make no sense
> in this case reduce slowly till the summery change
Current Mods | Mod Base | php(BB) programming | No help via PM

sbloomer
Registered User
Posts: 87
Joined: Fri Jun 12, 2009 8:18 pm

Re: Attachment files - Can I resize them?

Post by sbloomer » Wed Jul 06, 2011 11:47 am

4_seven wrote:sorry for comment, but of course this script works
and of course it really reduces image-size + file-size.
Thanks 4_seven

I was looking for this specific functionality but couldnt find an "official" mod - only this thread, and I needed to reaffirm for myself it worked because as a non-developer I have no point of reference, and there were no others who responded.

sbloomer
Registered User
Posts: 87
Joined: Fri Jun 12, 2009 8:18 pm

Re: Attachment files - Can I resize them?

Post by sbloomer » Wed Jul 06, 2011 12:14 pm

4_seven wrote:
sbloomer wrote:Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19008 bytes) in xx/forum/includes/functions_upload.php on line 297.
fine, that you have direct server access (and enough available ram) and have fixed that.]
I actually just asked the host to make sure the memory was at 64MB which it was originally - not sure why (or how) it changed, but i have been moving things around to relaunch my site. the htaccess fix gets the Internal Server Error, so it looks like my only recourse is to ask whether the host will up my memory limit even further.

dan filipi
Registered User
Posts: 82
Joined: Fri Dec 21, 2007 6:36 pm

Re: Attachment files - Can I resize them?

Post by dan filipi » Tue Sep 30, 2014 1:30 am

I know this is an old thread but I wanted to chime in about this MOD that is does work very well and I have had no complaints from any of my users of the resized images.
Actually, because it does auto resize the images I haven't had any issues from members that they cannot upload attachments because it is too large like we used to since I started using this MOD a couple months ago which is a load off the admins.

FYI, I found also that this MOD resizes uploaded images to phpBB Gallery by nickvergessen which is a big plus!

Granted some may not like this function, like for a site that doesn't want any degradation of the images by resizing them (I can't imagine a site like that even thinking about saving server space anyhow) but for most sites this MOD is all win.

I have been so pleased by the file size savings that I went and batch reduced ALL our gallery images which has shaved over 5 GB of server space!
Done properly it is VERY difficult to tell the difference in the images.
These savings are a big deal when on a VPS with a fixed storage space.

I have started resizing all the attachments prior to this MOD and expect to save an equal amount of server space.
Because this MOD is already in place all future gallery images and forum attachments are being resized so I won't ever have to go back to them like the old one's.

It took me awhile to figure out how to resize old attachments.
It's a 2 step process I'm using.
Using Irfanview, Batch convert and add the .jpg extension and bulk resize to 1280x960 but maintaining the aspect ratio.
Then use 'Bulk Rename Utility' to remove the .jpg file extension.
If anyone knows a one step process I'd sure like to hear about it. I have 90 attachments folders left to do.

Anyway, Thank you 4_seven for a MOD that should have been built in in the first place!

User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50894
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Attachment files - Can I resize them?

Post by stevemaury » Tue Sep 30, 2014 12:36 pm

What if the files aren't .jpgs?
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

dan filipi
Registered User
Posts: 82
Joined: Fri Dec 21, 2007 6:36 pm

Re: Attachment files - Can I resize them?

Post by dan filipi » Tue Sep 30, 2014 1:27 pm

stevemaury wrote:What if the files aren't .jpgs?
.mov clips have been uploaded as well as png's, gifs etc. and I haven't seen any problem with them with this MOD in place.
Honestly I don't know what my method of converting and resizing the old attachments is doing to them because it is so difficult and time consuming to find what format the original extensionless files are in so I'm not going to waste my time. In my case there are very few files in anything but a image format so I'm not concerned if an occasional animated gif is no longer animated by converting it.
After using Irfanview to convert them to jpg I check the file count and scan through the images to look for any errors. So far I haven't seen any.

As always, be smart and backup your files in binary so if a problem with the files are ever found they can be restored.

Locked

Return to “[3.0.x] Support Forum”