regenerate_thumbs.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /**
  20. * \file scripts/product/migrate_picture_path.php
  21. * \ingroup scripts
  22. * \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
  23. */
  24. if (!defined('NOSESSION')) {
  25. define('NOSESSION', '1');
  26. }
  27. $sapi_type = php_sapi_name();
  28. $script_file = basename(__FILE__);
  29. $path = __DIR__.'/';
  30. // Test if batch mode
  31. if (substr($sapi_type, 0, 3) == 'cgi') {
  32. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  33. exit(-1);
  34. }
  35. @set_time_limit(0); // No timeout for this script
  36. define('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".
  37. // Include and load Dolibarr environment variables
  38. require_once $path."../../htdocs/master.inc.php";
  39. require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
  40. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  41. require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
  42. // After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
  43. // $user is created but empty.
  44. // $langs->setDefaultLang('en_US'); // To change default language of $langs
  45. $langs->load("main"); // To load language file for default language
  46. // Global variables
  47. $version = DOL_VERSION;
  48. $error = 0;
  49. $forcecommit = 0;
  50. print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
  51. dol_syslog($script_file." launched with arg ".join(',', $argv));
  52. if (empty($argv[1])) {
  53. print "Usage: $script_file subdirtoscan\n";
  54. print "Example: $script_file produit\n";
  55. exit(-1);
  56. }
  57. print '--- start'."\n";
  58. $dir = DOL_DATA_ROOT;
  59. $subdir = $argv[1];
  60. if (empty($dir) || empty($subdir)) {
  61. dol_print_error('', 'dir not defined');
  62. exit(1);
  63. }
  64. if (!dol_is_dir($dir.'/'.$subdir)) {
  65. print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
  66. exit(2);
  67. }
  68. $filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
  69. global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
  70. foreach ($filearray as $keyf => $valf) {
  71. $ref = basename($valf['name']);
  72. $filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$');
  73. foreach ($filearrayimg as $keyi => $vali) {
  74. print 'Process image for ref '.$ref.' : '.$vali['name']."\n";
  75. // Create small thumbs for image
  76. // Used on logon for example
  77. $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
  78. if (preg_match('/Error/', $imgThumbSmall)) {
  79. print $imgThumbSmall."\n";
  80. }
  81. // Create mini thumbs for image (Ratio is near 16/9)
  82. // Used on menu or for setup page for example
  83. $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
  84. if (preg_match('/Error/', $imgThumbMini)) {
  85. print $imgThumbMini."\n";
  86. }
  87. }
  88. }
  89. $db->close(); // Close $db database opened handler
  90. exit($error);