Elxis CMS Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Elxis 4.x documentation for users and developers
 
Pages: [1] 2
  Print  
Author Topic: Limiting Avatar size  (Read 4772 times)
balisto
Jr. Member
**
Offline Offline

Posts: 71



« on: February 19, 2009, 21:57:49 »

Hello,

is there any way to limit the file size and physical size of user's avatar-pictures? I just realized that registered users upload, 0,5MB large pictures with 3076x2308 pixel  Undecided
Don't know why I didn't check that before, but I was sure that files were somehow resized on upload, but probably mixed that up with some other cms I tried before!?!

Does anybody have an idea how to do that?

Cheers,
Chris
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7588



WWW
« Reply #1 on: February 20, 2009, 08:13:02 »

Elxis resizes user avatars automatically to 100X100 pixels. It is strange that your user avatars are too big.
Check if you have GD2 library available in your PHP.

You can resize existing user avatars from within Elxis administration -> media manager -> avatars -> right click on an image -> resize.
Logged

balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #2 on: February 20, 2009, 09:23:09 »

hi datahell,

ha, so I was right. I was pretty sure that they used to be resized with my test installation. Yes GD works fine. Any idea, what else it could be? I moved the whole installation from my test-server to the live server previously. Perhaps something I forgot to change?

Chris
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7588



WWW
« Reply #3 on: February 20, 2009, 11:50:07 »

Elxis first uploads image to the images/avatars/ folder and makes it globally writable (permissions: 666).
Then checks image's size. If it is different than 100X100 pixel it resizes it.
In order for the resize to work properly it is required:
- GD2 library to be available.
- PHP's temporary folder to be writable.
- Image to be writable by PHP.

If the original uploaded avatar is owned by the local user and Elxis could not change permissions to the image after upload then PHP won't be able to overwrite the original image with the generated thumbnail. So, it might be a permissions issue. If you have enabled FTP access in Elxis global configuration make sure the settings are correct. You can use the Change mode Elxis tool to see the image owner and permissions and try to change permissions. If you are able to change permissions your system works fine. Try to upload a new avatar and check afterwards apache's error log. Did you see any error? Elxis tmpr/ folder should always be writable by PHP (permissions: 777 or 755 if you use SUPHP).
Logged

balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #4 on: February 20, 2009, 15:47:58 »

Hi Datahell,

thanks for keeping on this issue with me.

I checked everything and FTP and chmod works fine. I tested a bit and I found out that it depends on the file size. If the file size is smaller than about 1,5MB everything works as it should. If the file size is larger than that the file is not resized (and when I check in MediaManager, there is an icon saying "file size exceed" instead of the thumb). Actually after uploading a picture larger than 1,5 MB for a cupple of miliseconds I see 2 red php-error bars, but it directly fowards to the confirmation page saying "You profile has been saved" so that I never get the chance to click on them to see what it says... Did this file size thing give you any idea?

P.S. just realized another interesting behaviour: if I rightclick on a "normal" image thumb in MediaManager and then click on "resize" I get the resize dialogue as expected (and resizing works fine). If I do the same on one of the "file size exceed" thumbs, it just fowards to the huge picture (whole browser window) without giving me any possibility to resize.

P.P.S. I know that it doesn't make sense that people upload avatars bigger than 1,5 MB (that's probably why I never realized this problem while testing), but unfortunately on a live site people do such straaaaaange things Roll Eyes

Chris
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7588



WWW
« Reply #5 on: February 20, 2009, 18:46:31 »

I just uploaded a 1.9MB image for avatar and was resized successfully to 100X100pixel (2.7kb).
I guess this is a limitation to your PHP. Do the following: Upload an image and be ready to click the stop ("X") button on your browser when you see the red error messages and before Elxis redirects you. You must be fast in this but you it can be done. When you succeed this click the error to see the detailed error report. Alternatively see the apache's error log, I am sure there is something interesting there about this error (maybe memory exceeded). Finally you can edit the corresponding file and comment or temporary delete the re-direct line in order Elxis not to redirect you after saving.
« Last Edit: February 20, 2009, 18:48:45 by datahell » Logged

balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #6 on: February 20, 2009, 18:58:56 »

Yes tried this already a few times, but never got to stop it in time. Will give it a try with Firefox  Tongue
Logged
balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #7 on: February 20, 2009, 19:05:15 »

Ha! It worked with FF  Grin So here are the results of the belgian jury:

Code:
PHP Erreur [Warning]
URI: index.php
Path: /components/com_user/user.php
Line: 744
imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error:
and
Code:
PHP Erreur [Warning]
URI: index.php
Path: /components/com_user/user.php
Line: 744
imagecreatefromjpeg() [function.imagecreatefromjpeg]: '<correct absolute path to my homepage, blablabla... htdocs>/images/avatars/68_bodylotion.jpg' is not a valid JPEG file
Logged
CREATIVE Options
Authorized Elxis Professional
Elxis Community
Hero Member
*****
Offline Offline

Posts: 2323


Professional services for Elxis CMS


WWW
« Reply #8 on: February 20, 2009, 19:13:15 »

Your server has available the GD2 library  ?
Logged

Online Booking Pro Template with split menu (Elxis 2009.3) | We introduce the service of transferring all the content from Elxis 2006.x / 2008.x / 2009.x to Elxis 4 !
balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #9 on: February 20, 2009, 19:17:17 »

that's what it says - and it des work perfectly for smaller pictures
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7588



WWW
« Reply #10 on: February 20, 2009, 19:33:57 »

It is a memory issue. When an jpeg image is loaded in the memory it needs more memory than the image's size. Tell your hosting provider to increase the allocated memory to PHP if you wish to handle large images.

Here are the benchmark results I found on the internet.

For an initial image of 262kb:
Load JPEG: allocated memory increases to 4.1 MB
Create Thumbnail: allocated memory increases to 4.4 MB
Destroy JPEG: allocated memory decreases to 1.5 MB

So, for a 2mb image the allocated memory could be huge...

More info here:
http://www.corephp.co.uk/archives/42-Interesting-memory-use-with-GD-images.html
Logged

balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #11 on: February 20, 2009, 19:52:28 »

Hi - OK. Thanks for giving a solution. I will check that, but I guess 1&1 is not the hoster to discuss such things with  Roll Eyes
On the other hand: I don't necessarily want to handle large images (it's more the users that are obviously to lazy to bring their images to a smaller file size before uploading them). I would also be happy just to tell my users you cannot upload images larger than 1MB and if they do, they just get an error message (and the pic is not uploaded). Is there some possibilty to manually limit the allowed max. file size of avatar uploads or would that be a big hack?
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7588



WWW
« Reply #12 on: February 20, 2009, 20:43:53 »

It is easy to add a size limitation.

components/com_user/user.php
go to line 650:
$file = $_FILES['upavatar'];

add bellow:
if ($file['size'] < 102400) {

go to line 674:
}
Add bellow an other one }

Now only images smaller than 100kb will be uploaded.

All together:

if ( isset($_FILES['upavatar']) && is_array($_FILES['upavatar'])) {
     $file = $_FILES['upavatar'];
     if ($file['size'] < 102400) {

            $avname = eUTF::utf8_strtolower($file['name']);
            ................
        }
}

if ($newavatar) {
         ................
}


You can change 100kb to anything you like but you have to write the value in bytes (multiply X 1024, i.e.: 250 * 1024).
« Last Edit: February 20, 2009, 20:48:12 by datahell » Logged

balisto
Jr. Member
**
Offline Offline

Posts: 71



« Reply #13 on: February 20, 2009, 20:48:21 »

COOL! Thanks so much. Going to try that. Can I add an error message for the user the same way ("You file couldn't be uploaded because it's bigger than 1MB")?
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7588



WWW
« Reply #14 on: February 20, 2009, 21:50:54 »

The image upload is being executed after saving user's profile, so alerting him a message and redirecting him back would be confusing. The best solution would be to modify the message the user sees after saving his profile data (i.e. "Your profile was saved but the avatar upload failed, please use a smaller image."). You can set the message that will be displayed to the user by modifying the $mosmsg parameter in the mosRedirect function.

Example:
mosRedirect('page that will be redirected to', 'message that will be displayed');
Logged

Pages: [1] 2
  Print  
 
Jump to: