regenerate_thumbs.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file scripts/product/migrate_picture_path.php
  22. * \ingroup scripts
  23. * \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+
  24. */
  25. $sapi_type = php_sapi_name();
  26. $script_file = basename(__FILE__);
  27. $path = __DIR__.'/';
  28. // Test if batch mode
  29. if (substr($sapi_type, 0, 3) == 'cgi') {
  30. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  31. exit(-1);
  32. }
  33. @set_time_limit(0); // No timeout for this script
  34. 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".
  35. // Include and load Dolibarr environment variables
  36. require_once $path."../../htdocs/master.inc.php";
  37. require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
  38. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  39. require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
  40. // After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
  41. // $user is created but empty.
  42. // $langs->setDefaultLang('en_US'); // To change default language of $langs
  43. $langs->load("main"); // To load language file for default language
  44. // Global variables
  45. $version = DOL_VERSION;
  46. $error = 0;
  47. $forcecommit = 0;
  48. print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
  49. dol_syslog($script_file." launched with arg ".join(',', $argv));
  50. if (empty($argv[1])) {
  51. print "Usage: $script_file subdirtoscan\n";
  52. print "Example: $script_file produit\n";
  53. exit(-1);
  54. }
  55. print '--- start'."\n";
  56. $dir = DOL_DATA_ROOT;
  57. $subdir = $argv[1];
  58. if (empty($dir) || empty($subdir)) {
  59. dol_print_error('', 'dir not defined');
  60. exit(1);
  61. }
  62. if (!dol_is_dir($dir.'/'.$subdir)) {
  63. print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
  64. exit(2);
  65. }
  66. $filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
  67. global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
  68. foreach ($filearray as $keyf => $valf) {
  69. $ref = basename($valf['name']);
  70. $filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$');
  71. foreach ($filearrayimg as $keyi => $vali) {
  72. print 'Process image for ref '.$ref.' : '.$vali['name']."\n";
  73. // Create small thumbs for image
  74. // Used on logon for example
  75. $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
  76. if (preg_match('/Error/', $imgThumbSmall))
  77. print $imgThumbSmall."\n";
  78. // Create mini thumbs for image (Ratio is near 16/9)
  79. // Used on menu or for setup page for example
  80. $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
  81. if (preg_match('/Error/', $imgThumbMini))
  82. print $imgThumbMini."\n";
  83. }
  84. }
  85. $db->close(); // Close $db database opened handler
  86. exit($error);