dolibarr 21.0.0-alpha
regenerate_thumbs.php
Go to the documentation of this file.
1#!/usr/bin/env php
2<?php
3/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (!defined('NOSESSION')) {
27 define('NOSESSION', '1');
28}
29
30$sapi_type = php_sapi_name();
31$script_file = basename(__FILE__);
32$path = __DIR__.'/';
33
34// Test if batch mode
35if (substr($sapi_type, 0, 3) == 'cgi') {
36 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
37 exit(1);
38}
39
40@set_time_limit(0); // No timeout for this script
41define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
42
43// Include and load Dolibarr environment variables
44require_once $path."../../htdocs/master.inc.php";
45require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
46require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
47require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
48require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
49// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
50// $user is created but empty.
51
52// $langs->setDefaultLang('en_US'); // To change default language of $langs
53$langs->load("main"); // To load language file for default language
54
55// Global variables
56$version = DOL_VERSION;
57$error = 0;
58$forcecommit = 0;
59
60$hookmanager->initHooks(array('cli'));
61
62/*
63 * Main
64 */
65
66print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
67dol_syslog($script_file." launched with arg ".join(',', $argv));
68
69if (empty($argv[1])) {
70 print "Usage: $script_file subdirtoscan\n";
71 print "Example: $script_file produit\n";
72 exit(1);
73}
74
75print '--- start'."\n";
76
77$dir = DOL_DATA_ROOT;
78$subdir = $argv[1];
79if (empty($dir) || empty($subdir)) {
80 dol_print_error(null, 'dir not defined');
81 exit(1);
82}
83if (!dol_is_dir($dir.'/'.$subdir)) {
84 print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
85 exit(2);
86}
87
88$filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
89
90global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
91
92foreach ($filearray as $keyf => $valf) {
93 $ref = basename($valf['name']);
94 $filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp|\.webp)$', '(\.meta|_preview.*\.png)$');
95 foreach ($filearrayimg as $keyi => $vali) {
96 print 'Process image for ref '.$ref.' : '.$vali['name']."\n";
97
98 // Create small thumbs for image
99 // Used on logon for example
100 $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
101 if (preg_match('/Error/', $imgThumbSmall)) {
102 print $imgThumbSmall."\n";
103 }
104
105 // Create mini thumbs for image (Ratio is near 16/9)
106 // Used on menu or for setup page for example
107 $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
108 if (preg_match('/Error/', $imgThumbMini)) {
109 print $imgThumbMini."\n";
110 }
111 }
112}
113
114$db->close(); // Close $db database opened handler
115
116exit($error);
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_is_dir($folder)
Test if filename is a directory.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).