util.getfiles.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. $dirpath = './items/src';
  6. $return = [];
  7. $files = array();
  8. $dir = opendir($dirpath); // open the cwd..also do an err check.
  9. while(false != ($file = readdir($dir))) {
  10. if(($file != ".") and ($file != "..") and ($file != "index.php")) { $files[] = $file; }
  11. }
  12. natsort($files);
  13. $item_id = 0;
  14. $rows = 6;
  15. $cols = 6;
  16. foreach($files as $file) {
  17. $src = imagecreatefrompng('./items/src/'.$file);
  18. for($r = 0; $r < $rows; $r++) {
  19. for($c = 0; $c < $cols; $c++) {
  20. $dest = imagecreatetruecolor(42,42);
  21. imagesavealpha($dest, true);
  22. $trans_color = imagecolorallocatealpha($dest, 0, 0, 0, 127);
  23. imagefill($dest, 0, 0, $trans_color);
  24. imagecopy($dest, $src, 0,0, ($c*42), ($r*42), 42, 42);
  25. imagepng($dest, './items/out/'.$item_id.'.png');
  26. imagedestroy($dest);
  27. $item_id++;
  28. }
  29. }
  30. imagedestroy($src);
  31. }
  32. echo'<pre>'.print_r($return,1).'</pre>';
  33. ?>