Resize Attached Images (Updated for 2.0 RC4)

Started by Kays, October 17, 2009, 04:19:10 PM

Previous topic - Next topic

Kays

It only happens with new images. From what I can see so far is that it does get resized to a jpeg. But after that it get's changed to a .png. If I resize the .png as an existing image it will resize as a jpeg this time.

One temporary solution until i find a fix. In Post.php look for the following and either comment it out or remove it.


// Added for the Image resize mod
if(list ($width, $height, $type) = @getimagesize($_FILES['attachment']['tmp_name'][$n]))
{
if($type != 'IMAGETYPE_JPEG' || $width > $modSettings['max_image_width'] || $height > $modSettings['max_image_height'])
{
// What size should this image be?
$width = $width > $modSettings['max_image_width'] ? $modSettings['max_image_width'] : $width;
$height = $height > $modSettings['max_image_height'] ? $modSettings['max_image_height'] : $height;

// Resize it
require_once($sourcedir . '/Subs-Graphics.php');
if(saveAsJpeg($_FILES['attachment']['tmp_name'][$n], $width, $height, $_FILES['attachment']['tmp_name'][$n]))
{
// Find the new size.
$_FILES['attachment']['size'][$n] = filesize($_FILES['attachment']['tmp_name'][$n]);

// Change the file name if it's not a .jpg
if(strrchr($_FILES['attachment']['name'][$n], '.') != '.jpg')
$_FILES['attachment']['name'][$n] = substr($_FILES['attachment']['name'][$n], 0, -(strlen(strrchr($_FILES['attachment']['name'][$n], '.')))) . '.jpg';
}
}
}
// End Image resize mod
 

This will resize any images when they are viewed rather than when uploaded.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Makar

thanks try
I'll write about the results

Sorry for my english

hellbent64

so my forums has been acting buggy for awhile now...  i think ultimate shoutbox buggered something up.
found out today i have 6584 pages of attachment thumbnails and found out its this conflict with highslide and 1.1 of resize.

well i uploaded and ran the clean_thumbs.php and get this error:
Fatal error: Cannot redeclare ssi_shout() (previously declared in D:\Hosting\4508226\html\APforums\SSI.php:1571) in D:\Hosting\4508226\html\APforums\SSI.php on line 1585

i tried uninstalling shoutbox but i still get this error.
i am running
SMF Package SMF 1.1.11

any advice for me?

Kays

Take a look in SSI.php at those mentioned lines and you'll probably see some code for the shoutbox which is duplicated. Since you have the shoutbox removed, you should be safe to remove all of that code.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

hellbent64

sorry, i dont know much about php.   i removed the lines and it cleared up about 59000 images!
thanks!

Makar

Quote from: Kays on April 07, 2010, 09:44:55 AM
One temporary solution until i find a fix..................

as a temporary solution came
but
had to increase the limit from 206 kb to 1024kb for one picture
otherwise the image is larger than 206kb does not load and resize

Sorry for my english

Sorry for my english

hotrod007

I'm Getting this Error on a couple pages.  SMF 1.1.11

http://njsaltwaterfisherman.com/forums/index.php?topic=15031.160

Database Error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Custom Plugs.jpg'
WHERE ID_ATTACH = 26752
LIMIT 1' at line 2
File: /var/www/vhosts/njsaltwaterfisherman.com/httpdocs/forums/Sources/Display.php
Line: 1229

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.11, while your database is at version 1.1.1. The above error might possibly go away if you execute the latest version of upgrade.php.


Also my error log is filled with Errors.. like this.


Apply Filter: Only show the errors with the same message
Attachment not found: /var/www/vhosts/njsaltwaterfisherman.com/httpdocs/forums/attachments/27483_ad8364f6c47f6ed32ee3cf87817d1e762a63d6b3


Apply Filter: Only show the errors with the same message
2: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open '/var/www/vhosts/njsaltwaterfisherman.com/httpdocs/forums/attachments/14237_SGtogSP10707_jpg41e51d95dde49d647d2eb03e69ba5718' for writing
File: /var/www/vhosts/njsaltwaterfisherman.com/httpdocs/forums/Sources/Subs-Graphics.php
Line: 1732



I am Afraid what will happen if I uninstall this mode now... :-[

Kays

Removing the mod might or might not get rid of that error. It looks like that file is missing in the attachments folder.

In the Admin CP > Attachments and Avatars > File Maintenance. At the end of this line Total Size of Attachment Directory is a [Maintain] link. Click on that and run any suggested tasks.

Also, it appears that your database is way outdated. Download the large upgrade package, extract the upgrade.php and the .sql files and upload them to the root of your forums. Then run upgrade.php. Do backup your database first before doing so.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

hotrod007

#88
I did as you said.  but the Script to maintain has been running for the last 15 minutes..

Not done yet!
To avoid overloading your server, the process has been temporarily paused. It should automatically continue in a few seconds. If it doesn't, please click continue below.

I never had the data base error before..  Do we think the resizer is what caused it because of the old version?

I never updated the data base version.. didn't know I needed to..

I love this mode. I hope I get get this worked out.

I'm afraid of these updates.. always worried I'm going to lose something..

Where do I find the update script..



Edit.  I removed the Mod.  and everything is back to norm..  I would like to try and the the update and then reinstall it.  Maybe it will then run right?

Kays

It might take a little while to run but not that long I would think.

Since 1.1.1 there have been several changes made to the database. Some of it to do with attachments. But the mod should work fine on older versions.

As for updating, you can download the large  upgrade package from here. All that's required from it are the upgrade.php and the .sql files. I think there's two of them.

Do backup your database first. (How do I backup my database?)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

hotrod007

#90
Thanks Kays for your help..  My Host is backing up everything.  I'll run the update tonight.. then reinstall and see what happens.. I love this Mod. I hope I can get it to work.

So When I did the automatic updating from my old version.  This PHP File wasn't included..?


Kays

When an auto update is run the database upgrade should be a part of the process. But it looks like that got skipped in your case.

Did that maintenance routine finally finish running?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

hotrod007

No  I ran it again after removing the Mod.  and it still hung for 10 minutes..

Updates scare me :P

Kays

Without the mod, are you still getting those errors now?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

hotrod007

#94
NO All cleaned up.  that link I post with that Error.   The post was actually missing. and the images.
when I removed the mod.  the post and images came back and all errors are gone now.

I really need this Mod.  My members aren't very good at resizing.. :o

Kays

Hi, sorry about the delay. I've updated it for 1.x and hopefully this should correct you problems.



Updated for 2.0 RC3

Due to a number of problem with attachments in 2.0 RC3 and the changes I have done a major rewrite of the mod and updated to to address a numbers of problems associated with image files. Some of the fixes include.

- White screen of death when uploading larger files
- Reencoded images now preserve the file format.
- Disabled duplicate file name checking.
-  Added a warning message if GD is not available.
- Better support for bitmap images.

Features added in the Attachment settings in the Admin CP.
- The ability to set a max width and height for attached images separately rather than using the values for posted images
- The ability to set the jpeg compression factor.
- The option to save thumbnail either as .jgp or .png. independent of the avatar setting.
- Change existing  .png images back to .jpg.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

hotrod007

Cool Kay..  this may correct My? Problem..  I'm afraid to do the Database update.. :-\

Bugo

Russian translation (look at attachments) for ANSI & UTF-8 charsets.

Spuds

Kays,

Awesome mod, just what I needed with users that rather upload a large image and let the forum do the resize work, those 10 megapixel cameras and fast internet access have really change the way people interact with forums and this mod is needed.

While doing some testing (RC3) I uploaded a large image, 2592x1944 about 2.2M, and had the admin settings of max width and max height set to 1024.   When the file uploaded it was resized but to 1365x1024 (and now 200K sweet).  Anyway I was surprised by the 1365 dimension since I had set a max to 1024.

Kays

Hi Spuds. thanks for that. It looks like there was a problem with the script. I've corrected that

Thanks for the translation Bugo. It has been added.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Advertisement: