resize.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. $maxCount = 4;
  3. $count = 0;
  4. $resizeCount = 0;
  5. $folderIndex = 0;
  6. if (isset($_GET["folder"]))
  7. $folderIndex = $_GET["folder"];
  8. $srcFolder = "pictures/";
  9. $destFolder = "pictures_new/";
  10. $folders = array("Standesamt/",
  11. "Shooting/",
  12. "Gruppen/",
  13. "Fotobooth/",
  14. "Feier/");
  15. $folder = $srcFolder . $folders[$folderIndex];
  16. if (!is_dir($destFolder . $folders[$folderIndex])) {
  17. mkdir($destFolder . $folders[$folderIndex]);
  18. }
  19. if (is_dir($folder)) {
  20. if ($dh = scandir($folder)) {
  21. for ($i = 0; $i < count($dh); ++$i) {
  22. $file = $dh[$i];
  23. if ($file == "." || $file == "..")
  24. continue;
  25. if (is_dir($folder . $file))
  26. continue;
  27. if (file_exists($destFolder . $folders[$folderIndex] . $file))
  28. continue;
  29. if ($resizeCount < $maxCount) {
  30. resize($folder . $file, $destFolder . $folders[$folderIndex] . $file, 1920, 1080);
  31. ++$resizeCount;
  32. }
  33. }
  34. }
  35. }
  36. function resize($name, $filename, $w, $h)
  37. {
  38. echo "resize: " . $name . " -> " . $filename;
  39. echo "<br>";
  40. $system = explode('.', $name);
  41. if (preg_match('/jpg|jpeg/', $system[1])) {
  42. $src_img = imagecreatefromjpeg($name);
  43. }
  44. if (preg_match('/png/', $system[1])) {
  45. $src_img = imagecreatefrompng($name);
  46. }
  47. if (!$src_img) {
  48. link("icons/image.png", $filename);
  49. return;
  50. }
  51. $old_w = imageSX($src_img);
  52. $old_h = imageSY($src_img);
  53. $new_w = $w;
  54. $new_h = $h;
  55. if ($old_w > $old_h)
  56. $new_h = $old_h * ($new_w/$old_w);
  57. if ($old_w < $old_h)
  58. $new_w = $old_w * ($new_h/$old_h);
  59. echo "<br>";
  60. echo $old_w ."x" . $old_h;
  61. echo " -> ";
  62. echo $new_w ."x" . $new_h;
  63. echo "<br><br>";
  64. $dst_img=ImageCreateTrueColor($new_w, $new_h);
  65. imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $old_w, $old_h);
  66. if (preg_match("/png/",$system[1])) {
  67. imagepng($dst_img, $filename, 90);
  68. } else {
  69. imagejpeg($dst_img, $filename, 90);
  70. }
  71. imagedestroy($dst_img);
  72. imagedestroy($src_img);
  73. }
  74. $refreshUri = $PHP_SELF;
  75. if ($resizeCount == 0)
  76. $folderIndex++;
  77. $refreshUri .= "?folder=".$folderIndex;
  78. if ($folderIndex > count($folders))
  79. $refreshUri = "index.php";
  80. ?>
  81. <html>
  82. <head>
  83. <title> Resizer </title>
  84. <META HTTP-EQUIV="refresh" CONTENT="1;URL=<? echo $refreshUri; ?>">
  85. </head>
  86. <body>
  87. </body>
  88. </html>