| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- $maxCount = 4;
- $count = 0;
- $resizeCount = 0;
- $folderIndex = 0;
-
- if (isset($_GET["folder"]))
- $folderIndex = $_GET["folder"];
- $srcFolder = "pictures/";
- $destFolder = "pictures_new/";
- $folders = array("Standesamt/",
- "Shooting/",
- "Gruppen/",
- "Fotobooth/",
- "Feier/");
- $folder = $srcFolder . $folders[$folderIndex];
- if (!is_dir($destFolder . $folders[$folderIndex])) {
- mkdir($destFolder . $folders[$folderIndex]);
- }
- if (is_dir($folder)) {
- if ($dh = scandir($folder)) {
- for ($i = 0; $i < count($dh); ++$i) {
- $file = $dh[$i];
- if ($file == "." || $file == "..")
- continue;
-
- if (is_dir($folder . $file))
- continue;
-
- if (file_exists($destFolder . $folders[$folderIndex] . $file))
- continue;
-
- if ($resizeCount < $maxCount) {
- resize($folder . $file, $destFolder . $folders[$folderIndex] . $file, 1920, 1080);
- ++$resizeCount;
- }
- }
- }
- }
- function resize($name, $filename, $w, $h)
- {
- echo "resize: " . $name . " -> " . $filename;
- echo "<br>";
-
- $system = explode('.', $name);
- if (preg_match('/jpg|jpeg/', $system[1])) {
- $src_img = imagecreatefromjpeg($name);
- }
- if (preg_match('/png/', $system[1])) {
- $src_img = imagecreatefrompng($name);
- }
-
- if (!$src_img) {
- link("icons/image.png", $filename);
- return;
- }
-
- $old_w = imageSX($src_img);
- $old_h = imageSY($src_img);
-
- $new_w = $w;
- $new_h = $h;
-
- if ($old_w > $old_h)
- $new_h = $old_h * ($new_w/$old_w);
-
- if ($old_w < $old_h)
- $new_w = $old_w * ($new_h/$old_h);
-
- echo "<br>";
- echo $old_w ."x" . $old_h;
- echo " -> ";
- echo $new_w ."x" . $new_h;
- echo "<br><br>";
- $dst_img=ImageCreateTrueColor($new_w, $new_h);
- imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $old_w, $old_h);
-
- if (preg_match("/png/",$system[1])) {
- imagepng($dst_img, $filename, 90);
- } else {
- imagejpeg($dst_img, $filename, 90);
- }
- imagedestroy($dst_img);
- imagedestroy($src_img);
- }
- $refreshUri = $PHP_SELF;
- if ($resizeCount == 0)
- $folderIndex++;
-
- $refreshUri .= "?folder=".$folderIndex;
- if ($folderIndex > count($folders))
- $refreshUri = "index.php";
- ?>
- <html>
- <head>
- <title> Resizer </title>
- <META HTTP-EQUIV="refresh" CONTENT="1;URL=<? echo $refreshUri; ?>">
- </head>
- <body>
- </body>
- </html>
|