dolibarr 23.0.3
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28if (!defined('NOSESSION')) {
29 define('NOSESSION', '1');
30}
31
32$sapi_type = php_sapi_name();
33$script_file = basename(__FILE__);
34$path = __DIR__.'/';
35
36// Test if batch mode
37if (substr($sapi_type, 0, 3) == 'cgi') {
38 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
39 exit(1);
40}
41
42@set_time_limit(0); // No timeout for this script
43define('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".
44
45// Include and load Dolibarr environment variables
46require_once $path."../../htdocs/master.inc.php";
47require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
48require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
49require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
50require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
51// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
52// $user is created but empty.
59// $langs->setDefaultLang('en_US'); // To change default language of $langs
60$langs->load("main"); // To load language file for default language
61
62// Global variables
63$version = DOL_VERSION;
64$error = 0;
65$forcecommit = 0;
66
67$hookmanager->initHooks(array('cli'));
68
69/*
70 * Main
71 */
72
73print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
74dol_syslog($script_file." launched with arg ".implode(',', $argv));
75
76if (empty($argv[1])) {
77 print "Usage: $script_file subdirtoscan\n";
78 print "Example: $script_file produit\n";
79 exit(1);
80}
81
82print '--- start'."\n";
83
84$dir = DOL_DATA_ROOT;
85$subdir = $argv[1];
86if (empty($dir) || empty($subdir)) {
87 dol_print_error(null, 'dir not defined');
88 exit(1);
89}
90if (!dol_is_dir($dir.'/'.$subdir)) {
91 print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
92 exit(2);
93}
94
95$filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
96
97global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
98
99foreach ($filearray as $keyf => $valf) {
100 $ref = basename($valf['name']);
101 $filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp|\.webp)$', '(\.meta|_preview.*\.png)$');
102 foreach ($filearrayimg as $keyi => $vali) {
103 print 'Process image for ref '.$ref.' : '.$vali['name']."\n";
104
105 // Create small thumbs for image
106 // Used on logon for example
107 $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
108 if (preg_match('/Error/', $imgThumbSmall)) {
109 print $imgThumbSmall."\n";
110 }
111
112 // Create mini thumbs for image (Ratio is near 16/9)
113 // Used on menu or for setup page for example
114 $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
115 if (preg_match('/Error/', $imgThumbMini)) {
116 print $imgThumbMini."\n";
117 }
118 }
119}
120
121$db->close(); // Close $db database opened handler
122
123exit($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:64
dol_is_dir($folder)
Test if filename is a directory.
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).