#414 Photo Album Resize Original

1.x
open-accepted
5
2007-07-23
2007-07-19
No

Hi,

I'm re-entering this RFE (and patch) as the original one was stale and deleted, and the issue still exists in phpws 1.x photoalbums mod.

Issue: Although photoalbums gives the impression that it can resize over-sized images to a standard max (in the config file), it does not actually resize the original image and instead scales it using html. This achieves the illusion that large uploaded images have been resized, but in fact they are not, and page load speeds and bandwidth really suffers.

I would request that over-sized originals are actually resized when they are uploaded. This is the expected behaviour of most users anywise. The following patch will do the job in both single and batch uploads and is easy to implement.

1) In /mod/photoalbums/conf/config.php add the following

/* begin auto resize patch */
/* auto-resize originals, true or false */
define("PHOTOALBUM_RS", TRUE);
/* max width/height of resized originals */
define("PHOTOALBUM_RS_WIDTH", 500);
define("PHOTOALBUM_RS_HEIGHT", 500);
/* end auto resize patch */

2) In /mod/photoalbums/class/Photo.php do the following

insert between line 281 and 282

/* fix to standardize name case */
$name = strtolower($name);

between (new) 328 and 319 of Photo.php add...

/* begin auto-resize patch */
if(PHOTOALBUM_RS) {
$resized = PHPWS_File::makeThumbnail($this->_name, $dir, $dir, PHOTOALBUM_RS_WIDTH, PHOTOALBUM_RS_HEIGHT, TRUE);
if(!is_array($resized))
$resized->message("CNT_photoalbum");
if(is_file(PHOTOALBUM_DIR . $this->_album . "/" . $resized[0])) {
$this->_width = $resized[1];
$this->_height = $resized[2];
}
}
/* end auto-resize patch */

3) In /mod/photoalbums/class/Album.php do the following

insert before line 533

/* fix to standardize name case */
$name = strtolower($name);

between (new) 559 and 560

/* begin auto-resize patch */
if(PHOTOALBUM_RS) {
$resized = PHPWS_File::makeThumbnail($this->_batch[$key]['name'], $dir, $dir, PHOTOALBUM_RS_WIDTH, PHOTOALBUM_RS_HEIGHT, TRUE);
if(is_file($dir . $resized[0])) {
$this->_batch[$key]['width'] = $resized[1];
$this->_batch[$key]['height'] = $resized[2];
}
}
/* end auto-resize patch */

Discussion

  • Anonymous - 2007-07-20

    Logged In: YES
    user_id=400519
    Originator: NO

    I can put in these patches but this module is in serious need of a rewrite. Currently it is just a conversion.

     
  • Anonymous - 2007-07-20
    • assigned_to: nobody --> stardog
     
  • Verdon Vaillancourt

    Logged In: YES
    user_id=559731
    Originator: YES

    Hi Matt,

    Yes, I realize that :) I think though that in the meantime it will get used, and if it's not too hard to add, it might be a good idea. It might also help to have the precedent there for whoever does take on re-writing the mod.

    Anywise, I also noticed that when I tried this yesterday before posting, and had no errors, I didn't notice that in my example I left an old style content var for an error. Have a look where it says ...
    if(!is_array($resized))
    $resized->message("CNT_photoalbum");

    That should probably be something like
    if(!is_array($resized))
    exit('Resizing error');

     
  • Shaun Murray

    Shaun Murray - 2007-07-21

    Logged In: YES
    user_id=722742
    Originator: NO

    btw, I didn't get around to adding the path to the 0.x version. I was thinking it'd actually be better to store the original picture, the resized one and the thumbnail.

     
  • Anonymous - 2007-07-23
    • status: open --> open-accepted
     
  • Anonymous - 2007-07-23

    Logged In: YES
    user_id=400519
    Originator: NO

    I have added the information from above. Please confirm from subversion.

    Thank you,
    Matt

     
  • Verdon Vaillancourt

    Logged In: YES
    user_id=559731
    Originator: YES

    stardog, I'll have a look a bit later today. Thanks for this.

    singletrack, yes and no. I agree that would be good in many scenarios and wouldn't involve too much more work. It's certainly a part of a full-featured gallery like menalto's gallery. But it would have to be configurable. That said, from my own experience with clients, for the most part they weren't aware and didn't care about the original sizes being kept. The downside to keeping the full size originals, especially on a server where php is running as an apache module, is that the images end up being owned by the apache user and don't get counted against the actual user's quota. Ie. before I caught on to this on my standard cpanel server, and came up with a work around, I was finding clients with 300-500 MB quotas who actually had well over a GB of images not counting against their quotas.

     
  • Verdon Vaillancourt

    Logged In: YES
    user_id=559731
    Originator: YES

    Hi Matt,

    The changes to config.php and Album.php are fine. There is a problem with Photo.php. The resize code ended up in the wrong spot. Here is a diff, where the first file is the good one and the second is the problem one.

    verdon$ diff /Users/verdon/Sites/phpwebsite_1_2_0/mod/photoalbum/class/Photo.php /Users/verdon/Desktop/Photo_tmp.php
    283d282
    < $name = strtolower($name);
    319,327d317
    < if(PHOTOALBUM_RS) {
    < $resized = PHPWS_File::makeThumbnail($this->_name, $dir, $dir, PHOTOALBUM_RS_WIDTH, PHOTOALBUM_RS_HEIGHT, TRUE);
    < if(!is_array($resized))
    < $resized->message("CNT_photoalbum");
    < if(is_file(PHOTOALBUM_DIR . $this->_album . "/" . $resized[0])) {
    < $this->_width = $resized[1];
    < $this->_height = $resized[2];
    < }
    < }
    338a329,338
    > if(PHOTOALBUM_RS) {
    > $resized = PHPWS_File::makeThumbnail($this->_name, $dir, $dir,
    > PHOTOALBUM_RS_WIDTH, PHOTOALBUM_RS_HEIGHT, TRUE);
    > if(!is_array($resized))
    > $resized->message("CNT_photoalbum");
    > if(is_file(PHOTOALBUM_DIR . $this->_album . "/" . $resized[0])) {
    > $this->_width = $resized[1];
    > $this->_height = $resized[2];
    > }
    > }

     

Log in to post a comment.