root / gen_thumbs.php

View | Annotate | Download (2.5 KB)

1 51dc5aa5 Andreas
 #!/usr/bin/php
2 51dc5aa5 Andreas
 <?php
3 51dc5aa5 Andreas
4 6e2d319e Andreas
 /***************************************************************************
5 6e2d319e Andreas
  *
6 7617d447 Andreas
  * phpfspot, presents your F-Spot photo collection in Web browsers.
7 7617d447 Andreas
  *
8 7617d447 Andreas
  * Copyright (c) by Andreas Unterkircher
9 6e2d319e Andreas
  *
10 6e2d319e Andreas
  *  This program is free software; you can redistribute it and/or modify
11 6e2d319e Andreas
  *  it under the terms of the GNU General Public License as published by
12 6e2d319e Andreas
  *  the Free Software Foundation; either version 2 of the License, or
13 6e2d319e Andreas
  *  any later version.
14 6e2d319e Andreas
  *
15 6e2d319e Andreas
  *  This program is distributed in the hope that it will be useful,
16 6e2d319e Andreas
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 6e2d319e Andreas
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 6e2d319e Andreas
  *  GNU General Public License for more details.
19 6e2d319e Andreas
  *
20 6e2d319e Andreas
  *  You should have received a copy of the GNU General Public License
21 6e2d319e Andreas
  *  along with this program; if not, write to the Free Software
22 6e2d319e Andreas
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 6e2d319e Andreas
  *
24 6e2d319e Andreas
  ***************************************************************************/
25 6e2d319e Andreas
26 55677896 Andreas
27 55677896 Andreas
 /**
28 55677896 Andreas
  * gen_thumbs.php
29 55677896 Andreas
  *
30 55677896 Andreas
  * generate photo thumbnails on the console to avoid webserver overload
31 55677896 Andreas
  *
32 55677896 Andreas
  * @package phpfspot
33 55677896 Andreas
  */
34 9f1b0f06 Andreas
 if(!isset($_SERVER["TERM"])) {
35 9f1b0f06 Andreas
    print "<br /><br />This script should only be invoked from command line!<br />\n";
36 9f1b0f06 Andreas
    die;
37 9f1b0f06 Andreas
 }
38 9f1b0f06 Andreas
39 51dc5aa5 Andreas
 require_once "phpfspot.class.php";
40 51dc5aa5 Andreas
41 51dc5aa5 Andreas
 $fspot = new PHPFSPOT;
42 6a21b6f0 Andreas
 $fspot->fromcmd = true;
43 764ad0eb Andreas
44 aed571db Andreas
 $overwrite = false;
45 aed571db Andreas
46 aed571db Andreas
 $short_options = "";
47 aed571db Andreas
 $short_options.= "h"; /* help */
48 aed571db Andreas
 $short_options.= "o"; /* overwrite */
49 1dc0e2e5 Andreas
 $short_options.= "c"; /* cleanup */
50 aed571db Andreas
51 aed571db Andreas
 $long_options = array(
52 aed571db Andreas
    "help",
53 aed571db Andreas
    "overwrite",
54 1dc0e2e5 Andreas
    "cleanup",
55 aed571db Andreas
 );
56 aed571db Andreas
57 aed571db Andreas
 /* command line option specified? */
58 aed571db Andreas
 if(isset($_SERVER['argc']) && $_SERVER['argc'] > 1) {
59 aed571db Andreas
    /* validate */
60 aed571db Andreas
    $con = new Console_Getopt;
61 aed571db Andreas
    $args = $con->readPHPArgv();
62 aed571db Andreas
    $options = $con->getopt($args, $short_options, $long_options);
63 aed571db Andreas
64 aed571db Andreas
    if(PEAR::isError($options)) {
65 aed571db Andreas
       die ("Error in command line: " . $options->getMessage() . "\n");
66 aed571db Andreas
    }
67 aed571db Andreas
68 aed571db Andreas
    foreach($options[0] as $opt) {
69 aed571db Andreas
       switch($opt[0]) {
70 aed571db Andreas
          case 'h':
71 aed571db Andreas
          case '--help':
72 aed571db Andreas
             print "we need some help here!\n";
73 aed571db Andreas
             exit(0);
74 aed571db Andreas
             break;
75 aed571db Andreas
          case 'o':
76 aed571db Andreas
          case '--overwrite':
77 aed571db Andreas
             print "Overwrite flag set!\n";
78 aed571db Andreas
             $overwrite = true;
79 aed571db Andreas
             break;
80 1dc0e2e5 Andreas
          case 'c':
81 1dc0e2e5 Andreas
          case '--cleanup':
82 1dc0e2e5 Andreas
             $fspot->cleanup_phpfspot_db();
83 1dc0e2e5 Andreas
             exit(0);
84 1dc0e2e5 Andreas
             break;
85 aed571db Andreas
          default:
86 aed571db Andreas
             print "invalid option";
87 aed571db Andreas
             exit(1);
88 aed571db Andreas
             break;
89 aed571db Andreas
       }
90 aed571db Andreas
    }
91 aed571db Andreas
 }
92 aed571db Andreas
93 764ad0eb Andreas
 $all = $fspot->getPhotoSelection();
94 764ad0eb Andreas
95 764ad0eb Andreas
 foreach($all as $photo) {
96 aed571db Andreas
    $fspot->gen_thumb($photo, $overwrite);
97 764ad0eb Andreas
 }
98 51dc5aa5 Andreas
99 51dc5aa5 Andreas
 ?>