regenerate_thumbs.php 3.7 KB

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