Announcement

#1 2008-03-18 04:13:01

Lachette
Member
2008-03-18
7

Automatic Thumbnails?

If i read the home page correctly, PWG can create my thumbnails for me automatically. Is this correct?

If that is correct:
What am I doing wrong in this situation?

Install PWG into a web enabled directory
Ran the installer
(at this point it says its installed correctly and im able to log in as admin)

Upload images via ftp (about 1000 of them with subdirectories) into the galleries folder within PWG directory.

Go into syncronization and tell it to sync.
It will add the directories, but won't add the images since they have missing thumbnails ("PWG-UPDATE-2 (missing thumbnail)" error)

the only way it ever syncs the images is when i manually go to the thumbnails page to create the thumbs 20 at a time. (it takes a long time for 1000+ images eg. 1000/20=500 iterations)

Is this the only way to create thumbnails in 1.7.1? I don't want to create thumbs on a local computer as uploading the orig plus thumbs is a waste of time when they can be made on the server side.

on a note, i have made a mod to the file site_update.php
line 261:
from
  if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir))
to
  if (preg_match('/^[a-zA-Z0-9-_. ]+$/', $dir))

adding the space between the . and the ]. this was done so it could accept directories with spaces in them. with this mod in there, it will still sync correctly provided i create the thumbs via the thumbnails page in the admin panel.





if you need more info please let me know.

Thanks for the help in advance.

Last edited by Lachette (2008-03-18 04:50:12)

Offline

 

#2 2008-03-18 08:44:04

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: Automatic Thumbnails?

Where did you read that thumbnails could be created automatically?

There is an option to create missing thumbnails.

Thumbnail creation couldn't be done with spaced filenames.
8-)


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 

#3 2008-03-18 14:00:17

Lachette
Member
2008-03-18
7

Re: Automatic Thumbnails?

VDigital wrote:

Where did you read that thumbnails could be created automatically?

Frome the PWG front page:

Easy Input

Create a folder on your server, FTP your images, click on Synchronize in the admin interface: you are done. Your images will appear neatly filed in a new category named after the folder. Thumbnails can be automatically generated, or you can upload your own. EXIF and IPTC metadata are automatically recognized.

PhpWebGallery can handle more than pictures, but any kind of files. You can then integrate videos, PDF files, sounds, documents, whatever.

VDigital wrote:

Thumbnail creation couldn't be done with spaced filenames.
8-)

My files themselves do not have spaces only the folders. And as i said earlier with the code mod i had posted it does work with spaces. provided i go in an tell it to make thumbnails.

I was hoping they did it automatically so i don't have to try to create 1000+ something pictures..

Offline

 

#4 2008-03-18 16:04:23

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: Automatic Thumbnails?

For 1000+
We recommend to prepare your pictures before publishing them.
Preparing for exemple with XnViews.
Preparing means:

- Keeping some High resolution and send them in the high_pwg subdirectory of the category
- resizing picture in the category folder in a web adapted size (~ 512px height)
- making your thumbnails in the thumbnail subdirectory of the category with prefixed filenames, resized files with adapted option.

And this can be done and controlled before publishing via many available scripts like
BuildPWGPicture or Encadre_Image or Gallery Mage, PhotoFiltre, ResizeMultiple, PhpMyVignettes, ... and many others.

8-)


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 

#5 2008-03-19 00:41:45

Lachette
Member
2008-03-18
7

Re: Automatic Thumbnails?

so... theres no future plans to have that built in like in gallery2? i would use that one but its bloated... i would prefer pwg but this is alot of overhead work...

Offline

 

#6 2008-03-19 06:52:53

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: Automatic Thumbnails?

I don't know when but will do like or better, but anyway in a simplier way.
8-)


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 

#7 2008-03-20 17:01:02

Lachette
Member
2008-03-18
7

Re: Automatic Thumbnails?

yea cause it would be nice... theres a few galleries out there that will create thumbnails when they are first viewed not when they are added so it reduces some server stress. but those apps (gallery2 in particular) gots too much crap to deal with...

if you got that auto thumbnail thing working in this, i would be set.

Offline

 

#8 2008-03-31 22:46:39

Duncane
Guest

Re: Automatic Thumbnails?

Here's a quick and dirty script that while allow you to generate thumbnails.

This script must be copied in the gallerie directory where thumbnails have to be created, and then launched on command line with a command like : php thumbscript.php .

I made this script in less than 10 minutes taking lots of code from the thumbnail.php in the admin section of my phpwebgallerie while facing the same problem than you.

If i've got enough time, i'll make a better one, which could be run from the root dir, and will browse every subdirs in galleries.

Note : i did not test it, but if some thumbnails are already present, i think this script will have a fatal error.

Enjoy :)

Code:

<?php
$newWidht=128;
$newHeight=128;
$tndir="thumbnail";
if( $dir = opendir("/path/to/the/gallerie/") )
{
while( FALSE !== ($fich = readdir($dir)) ) {
     if ($fich != "." && $fich != "..") {
  $ext = (pathinfo($fich));
  $extension = $ext["extension"];
  $path=$fich;
  unset ($srcImage);
  if (in_array($extension, array('jpg', 'JPG', 'jpeg', 'JPEG')))
  {
    $srcImage = @imagecreatefromjpeg($path);
  }
  else if ($extension == 'png' or $extension == 'PNG')
  {
    $srcImage = @imagecreatefrompng($path);
  }
  else
  {
    unset($extension);
  }

  if ( isset( $srcImage ) )
  {
    // width/height
    $srcWidth    = imagesx( $srcImage );
    $srcHeight   = imagesy( $srcImage );
    $ratioWidth  = $srcWidth/$newWidth;
    $ratioHeight = $srcHeight/$newHeight;

    // maximal size exceeded ?
    if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) )
    {
      if ( $ratioWidth < $ratioHeight)
      {
        $destWidth = $srcWidth/$ratioHeight;
        $destHeight = $newHeight;
      }
      else
      {
        $destWidth = $newWidth;
        $destHeight = $srcHeight/$ratioWidth;
      }
    }
    else
    {
      $destWidth = $srcWidth;
      $destHeight = $srcHeight;
    }
// GD 2.0 or more recent -> good results (but slower)
      $destImage = imagecreatetruecolor( $destWidth, $destHeight);
      imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0,
                          $destWidth,$destHeight,$srcWidth,$srcHeight );


    $dest_file = $tndir.'/TN-';
    $dest_file.= $ext['basename'];
    $dest_file.= '.jpg';

    // creation and backup of final picture
    imagejpeg($destImage, $dest_file);
    // freeing memory ressources
    imagedestroy( $srcImage );
    imagedestroy( $destImage );
}}
}
}
?>
 

#9 2008-03-31 22:50:15

Duncane
Guest

Re: Automatic Thumbnails?

woot there's a little bug that a mv with sed could help solve, the ['basename'] parameter of the pathinfo is including the extension.

Sorry :)

 

#10 2008-03-31 22:55:36

duncane
Guest

Re: Automatic Thumbnails?

Correct code for the end should be something like :

Code:

    $dest_file = $tndir.'/TN-';
    $dest_file.= basename($fich, $extension);
    $dest_file.= 'jpg';
 

#11 2008-04-01 03:26:30

Lachette
Member
2008-03-18
7

Re: Automatic Thumbnails?

Hey thanks for the help, Ill give it a shot tonight and let you know how it works.

Offline

 

#12 2008-04-01 22:19:33

duncane
Member
2008-04-01
14

Re: Automatic Thumbnails?

New recursive version that should deal with subdirs.

It has not yet been tested, so please be aware that i'm not responsible for any dysfunction that can happen.

Cheers

Note : i've also corrected a typo that was in the previous script : newWidth instead of newWidht

Code:

<?php
$newWidth=128;
$newHeight=128;
$tndir="thumbnail/";
$tnextension = 'jpg';
$tnprefix='TN-';
$pathDir = "/path/to/the/gallerie/";

//Thumbnail creation function
//recursively deals with subdir
function createThumbs ( $dirToDeal )
{
if( $dir = opendir($dirToDeal) )
{
if ( !is_dir ( $dirToDeal . $tndir ) )
  {
  mkdir ( $dirToDeal . $tndir );
  }
while( FALSE !== ($fich = readdir($dir)) )
  {
  if ( $fich != "." && $fich != ".." && is_file ($fich) )
    {
    if ( is_dir ( $fich ) )
      {
      createThumbs ($fich);
      }
    else
      {
    $explodedFileName = (pathinfo($fich));
    $extension = $explodedFileName["extension"];
    $path=$fich;
    unset ($srcImage);
    if (in_array($extension, array('jpg', 'JPG', 'jpeg', 'JPEG')))
      {
      $srcImage = @imagecreatefromjpeg($path);
      }
    else if ($extension == 'png' or $extension == 'PNG')
      {
      $srcImage = @imagecreatefrompng($path);
      }
    else
      {
      unset($extension);
      }
    
    if ( isset( $srcImage ) )
      {
      // width/height
      $srcWidth    = imagesx( $srcImage );
      $srcHeight   = imagesy( $srcImage );
      $ratioWidth  = $srcWidth/$newWidth;
      $ratioHeight = $srcHeight/$newHeight;

      // maximal size exceeded ?
      if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) )
        {
        if ( $ratioWidth < $ratioHeight)
          {
          $destWidth = $srcWidth/$ratioHeight;
          $destHeight = $newHeight;
          }
        else
          {
          $destWidth = $newWidth;
          $destHeight = $srcHeight/$ratioWidth;
          }
        }
      else
        {
        $destWidth = $srcWidth;
        $destHeight = $srcHeight;
        }
      // GD 2.0 or more recent -> good results (but slower)
      $destImage = imagecreatetruecolor( $destWidth, $destHeight);
      imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0,
                          $destWidth,$destHeight,$srcWidth,$srcHeight );

      $dest_file = $explodedFileName["dirname"] . "/" . $tndir . $tnprefix;
      $dest_file.= $explodedFileName["filename"];
      $dest_file.= "." . $tnextension;

      // creation and backup of final picture
      imagejpeg($destImage, $dest_file);
      // freeing memory ressources
      imagedestroy( $srcImage );
      imagedestroy( $destImage );
      }
      }
    }
  }
}
}

//Launching with the first dir
createThumbs ( $pathDir );

?>

Last edited by duncane (2008-04-01 22:20:31)

Offline

 

#13 2008-04-01 22:27:16

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: Automatic Thumbnails?

What are you doing?
What does your script do more than Admin > Pictures > Thumbnails ?

I don't understand exactly.

Could you test and explain differences between both solutions?

Thanks.

8-)


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 

#14 2008-04-02 14:24:28

duncane
Member
2008-04-01
14

Re: Automatic Thumbnails?

This script is designed to be launched directly in the command line prompt, when having a timeout parameter in your apache config which is setup to a too low value to generate a whole set of thumbnails (200+).

Basicaly, this script was not written to replace the admin page, it's designed to be used as a optionnal function.

Regards,

Last edited by duncane (2008-04-02 14:27:45)

Offline

 

#15 2008-04-02 21:04:57

Lachette
Member
2008-03-18
7

Re: Automatic Thumbnails?

This is a really nice solution to have, it will even be nicer if/when duncane allows it to run from the root, then i could just run a cron job every hour or so. And yes, it bypasses the timeout issue when doing it via web. most web hosts dont let you jack with the timeout setting anyway so this is a good solution.

the only thing better is if PWG would just generate thumbs as needed. not at the point of adding, but at the point when it needs to be viewed. Gallery2 does this very well but at the same time its bloated with too many other things.

BTW Duncane, thank you so much for this script! Makes doing thumbs for 1000+ pics a breeze.

Last edited by Lachette (2008-04-02 21:05:48)

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2022 · Contact