Частый посетитель
Покинул форум
Сообщений всего: 879
Дата рег-ции: Март 2017
Откуда: Германия, Бавария
Помог: 37 раз(а)
|
DmitryVL пишет:Всем добрый день. Имеется большое количество папок с фото. Просмот этих папок происходит через
PHP:
скопировать код в буфер обмена
<?PHP $dir = 'img/'; function scan(string $dir) { } if(isset($_GET['product_id'])) { $product_folder = $dir.$_GET['product_id']; if( !is_dir($product_folder) ) { die('Папка не существует'); } $files = scan($product_folder); } foreach( $files as $file ) { $path = $product_folder.'/'.$file; echo "<a href=\"{$path}\"> <img src=\"{$path}\" style=\"width: 100px; height:100px;\"> </a>"; } } else { $folders = scan($dir); echo 'Папка пустая'; } else { foreach($folders as $folder) { echo "<p><a href=\"?product_id={$folder}\">{$folder}</a></p>"; } } }
всё хорошо, но изображения загружаются полностью все сразу, далее сжимаются до размера миниатюры.
Возможно ли подключить скрипт для просмотра фото, так что бы он загружал миниатюры меньшего качества.
Добрый день!
Вы можете подключить PHP скрипт для создания миниатюр.
и можете запускать его при закачки оригиналов на сервер и сохраненять их в папке thumbs, либо создавать их "налету" из оригиналов без сохранения.
Это две функция. makeQThumb создаёт квадратные миниатюры, makeQThumb создаёт миниатюры с пропорциями оригинала.Спойлер (Отобразить)PHP:
скопировать код в буфер обмена
<? function makeQThumb($source_img, $size, $save_img=null) { //-------------------------------------------------- switch ($type) { case 2: $ContentType="jpg"; break; case 3: $ContentType="png"; break; case 1: $ContentType="gif"; break; } if(!$save_img) header("Content-Type: image/$ContentType"); // Получаем размеры оригинального изображения // Превью // Горизонтальное изображение if ($width > $height && $width > $size) { imagecopyresampled($thumbs, $source, 0 , 0 , (($width-$height)/2 ), 0 , $size, $size, $height, $height); } // Вертикальное изображение elseif ($height > $width && $height > $size) { imagecopyresampled($thumbs, $source, 0 , 0 , 0 , (($height-$width)/2 ), $size, $size, $width, $width); } // Если квадрат elseif ($height == $width && $height > $size) { } // Изображение меньше размеров стороны else { $thumbs = $source; } //------------------------------------------------- if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: break; case 6: break; case 8: break; } } //-------------------------------------------------- if($save_img) { switch ($type) { case 2: break; case 3: $status = @imagepng($thumbs, $save_img); break; case 1: $status = @imagegif($thumbs, $save_img); break; } return $status; } else { // Выводим изображение switch ($type) { case 2: break; case 3: break; case 1: break; } } } //---------------------------------------------------------- function makeThumb($source_img, $new_w, $new_h, $save_img=null) { switch ($type) { case 2: $ContentType="jpg"; break; case 3: $ContentType="png"; break; case 1: $ContentType="gif"; break; } if(!$save_img) header("Content-Type: image/$ContentType"); //gets the dimmensions of the image // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions // resize the big image to the new created one // output the created image to the file. Now we will have the thumbnail into the file named by $save_img //------------------------------------------------- if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: break; case 6: break; case 8: break; } } //-------------------------------------------------- if($save_img) { switch ($type) { case 2: break; case 3: $status = @imagepng($dst_img, $save_img); break; case 1: $status = @imagegif($dst_img, $save_img); break; } return $status; } else { // Выводим изображение switch ($type) { case 2: break; case 3: break; case 1: break; } } }?>
Если "налету", то пишите или
Удачи!
|