标题: [其他] 如何将多个文件夹的图片批量生成单独的网页 [打印本页]
作者: xp3000 时间: 2019-9-20 17:31 标题: 如何将多个文件夹的图片批量生成单独的网页
有多个文件夹,里面有图片jpg,bmp,png格式,如何生成呢?
大概是这样的,需要在图片所在所有的目录内生成index.html
<!DOCTYPE html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<meta property="og:title" content="Kaya Yin"/>
<meta charset="GB2312">
<meta name="keywords" content="">
<title>Kaya Yin</title>
<link rel="stylesheet" href="../res/common.css?v=1.6.3">
</head>
<body>
<div id="carousel" class="carousel full-page">
<div id="pictures"></div>
</div>
<div id="thumbnailCollapse" class="left-bottom">
<div id="thumbIcons">
<div class="showThumbs"></div>
<div class="showThumbs"></div>
<div class="showThumbs"></div>
</div>
</div>
<div class="thumbs left-bottom">
<div class="thumbs-nav">
<div id="prevThumbs" class="icon-prev hidden"></div>
<div id="nextThumbs" class="icon-next hidden"></div>
</div>
<div id="thumbs" style="left: 0px">
<img src="1.jpg" data-href="1.jpg" alt="Photo-1"><img src="2.jpg" data-href="2.jpg" alt="Photo-2"><img src="3.jpg" data-href="3.jpg" alt="Photo-3"><img src="4.jpg" data-href="4.jpg" alt="Photo-4">
</div>
</div>
<div id="navigation" class="right-top">
<nav>
<a id="prev" class="icon-prev" title="Previous Image"> </a>
<a id="next" class="icon-next" title="Next Image"> </a>
</nav>
<div id="fullscreen">
<div id="fullscreenLogo" title="Go Fullscreen">
</div>
</div>
<div id="slideshow">
<div id="slideshowIcon" >
</div>
</div>
</div>
<div id="imageInfo" class="right-bottom">
<h2 id="imageCount"></h2>
</div>
<div id="sidebar" class="left-top">
<div id="folders">
<h2><a href="../index.html" class="folderTitle" style="margin-left:16px;" data-folderLevel="1">Home</a></h2>
</h2>
<h3><a class="folderTitle" style="margin-left:15px;" data-folderLevel="1">Kaya Yin</a></h3>
<div id="links" class="left-bottom">
<div class="sharing">
</div>
<script>window.jQuery || document.write('<script src="../res/jquery-1.10.2.min.js"><\/script>');</script>
<script src="../res/main.js"></script>
<script src="../res/jquery.touchSwipe.min.js"></script>
<script>
// Fully version: 1.6.3
if( $("html").hasClass("ie8") || $("html").hasClass("ie7") ) {
document.open();
document.body.innerHTML = '';
document.write(html);
document.close();
}
else {
$(window).load(function(){
initSkin({
animationInterval: 1000,
amountImages: 4,
wrapAround: true,
fontSize: 13,
showPhotoDataFromStart: false,
slideshowInterval: 3,
opacity: 30,
});
});
}
</script>
</body>
</html>
样本太大,分成两部分了
<title>图片目录</title>
amountImages: 图片数量,
有单个文件夹处理的工具太大不让发
作者: WHY 时间: 2019-9-22 18:25
本帖最后由 WHY 于 2019-9-28 16:28 编辑
- @echo off
- for /f "delims=:" %%i in ('findstr /n "^::::::" "%~f0"') do set "startLine=%%i"
- for /f "delims=" %%i in ('dir /b /ad /s * ^| findstr /i /v "\\res$"') do (
- set "img=" & set n=0
- set "fd=%%~nxi"
- pushd "%%i"
- for %%j in (*.jpg *.bmp *.png) do (
- set "f=%%j" & set /a n+=1
- setlocal enabledelayedexpansion
- for /f "delims=" %%k in ("!img!<img src="!f!" data-href="!f!" alt="Photo-!n!">") do (
- endlocal & set "img=%%k"
- )
- )
- popd
-
- if defined img (
- for /f "skip=%startLine% delims=" %%j in ('type "%~f0"') do (
- set "s=%%j"
- setlocal enabledelayedexpansion
- if "!s:<meta property=!" NEQ "!s!" (
- echo; ^<meta property="og:title" content="!fd!"/^>
- ) else if "!s:<title>=!" NEQ "!s!" (
- echo; ^<title^>!fd!^</title^>
- ) else if "!s:<img src=!" NEQ "!s!" (
- echo; !img!
- ) else if "!s:amountImages:=!" NEQ "!s!" (
- echo; amountImages: !n!,
- ) else if "!s:<h3>=!" NEQ "!s!" (
- echo; ^<h3^>^<a class="folderTitle" style="margin-left:15px;" data-folderLevel="1"^>!fd!^</a^>^</h3^>
- ) else echo;!s!
- endlocal
- )
- ) > "%%i\index.html"
- )
- pause & exit
-
- :::::: htmlCodeStart ::::::
- <!DOCTYPE html>
- <head>
- <meta name="viewport" content="initial-scale=1.0">
- <meta property="og:title" content="MyPhotoFolder"/>
- <meta charset="GB2312">
- <meta name="keywords" content="">
- <title>MyPhotoFolder</title>
- <link rel="stylesheet" href="../res/common.css?v=1.6.3">
- </head>
- <body>
- <div id="carousel" class="carousel full-page"><div id="pictures"></div></div>
- <div id="thumbnailCollapse" class="left-bottom">
- <div id="thumbIcons">
- <div class="showThumbs"></div><div class="showThumbs"></div><div class="showThumbs"></div>
- </div>
- </div>
- <div class="thumbs left-bottom">
- <div class="thumbs-nav">
- <div id="prevThumbs" class="icon-prev hidden"></div>
- <div id="nextThumbs" class="icon-next hidden"></div>
- </div>
- <div id="thumbs" style="left: 0px">
- <img src="1.png" data-href="1.png" alt="Photo-1">
- </div>
- </div>
- <div id="navigation" class="right-top">
- <nav>
- <a id="prev" class="icon-prev" title="Previous Image"> </a>
- <a id="next" class="icon-next" title="Next Image"> </a>
- </nav>
- <div id="fullscreen"><div id="fullscreenLogo" title="Go Fullscreen"></div></div>
- <div id="slideshow"><div id="slideshowIcon" ></div></div>
- </div>
- <div id="imageInfo" class="right-bottom"><h2 id="imageCount"></h2></div>
- <div id="sidebar" class="left-top">
- <div id="folders">
- <h2><a href="../index.html" class="folderTitle" style="margin-left:16px;" data-folderLevel="1">Home</a></h2>
- <h3><a class="folderTitle" style="margin-left:15px;" data-folderLevel="1">MyPhotoFolder</a></h3>
- <div id="links" class="left-bottom">
- <div class="sharing">
- </div>
- <script>window.jQuery || document.write('<script src="../res/jquery-1.10.2.min.js"><\/script>');</script>
- <script src="../res/main.js"></script>
- <script src="../res/jquery.touchSwipe.min.js"></script>
- <script>
- // Fully version: 1.6.3
- if( $("html").hasClass("ie8") || $("html").hasClass("ie7") ) {
- document.open();document.body.innerHTML = '';document.write(html); document.close();
- }else {
- $(window).load(function(){
- initSkin({
- animationInterval: 1000,
- amountImages: 4,
- wrapAround: true,
- fontSize: 13,
- showPhotoDataFromStart: false,
- slideshowInterval: 3,
- opacity: 30,
- });
- });
- }
- </script>
- </body></html>
复制代码
作者: WHY 时间: 2019-9-22 19:46
本帖最后由 WHY 于 2019-9-28 16:33 编辑
Test.ps1- $str = @'
- <!DOCTYPE html>
- <head>
- <meta name="viewport" content="initial-scale=1.0">
- <meta property="og:title" content="MyPhotoFolder"/>
- <meta charset="GB2312">
- <meta name="keywords" content="">
- <title>MyPhotoFolder</title>
- <link rel="stylesheet" href="../res/common.css?v=1.6.3">
- </head>
- <body>
- <div id="carousel" class="carousel full-page"><div id="pictures"></div></div>
- <div id="thumbnailCollapse" class="left-bottom">
- <div id="thumbIcons">
- <div class="showThumbs"></div><div class="showThumbs"></div><div class="showThumbs"></div>
- </div>
- </div>
- <div class="thumbs left-bottom">
- <div class="thumbs-nav">
- <div id="prevThumbs" class="icon-prev hidden"></div>
- <div id="nextThumbs" class="icon-next hidden"></div>
- </div>
- <div id="thumbs" style="left: 0px">
- <img src="1.png" data-href="1.png" alt="Photo-1">
- </div>
- </div>
- <div id="navigation" class="right-top">
- <nav>
- <a id="prev" class="icon-prev" title="Previous Image"> </a>
- <a id="next" class="icon-next" title="Next Image"> </a>
- </nav>
- <div id="fullscreen"><div id="fullscreenLogo" title="Go Fullscreen"></div></div>
- <div id="slideshow"><div id="slideshowIcon" ></div></div>
- </div>
- <div id="imageInfo" class="right-bottom"><h2 id="imageCount"></h2></div>
- <div id="sidebar" class="left-top">
- <div id="folders">
- <h2><a href="../index.html" class="folderTitle" style="margin-left:16px;" data-folderLevel="1">Home</a></h2>
- <h3><a class="folderTitle" style="margin-left:15px;" data-folderLevel="1">MyPhotoFolder</a></h3>
- <div id="links" class="left-bottom">
- <div class="sharing">
- </div>
- <script>window.jQuery || document.write('<script src="../res/jquery-1.10.2.min.js"><\/script>');</script>
- <script src="../res/main.js"></script>
- <script src="../res/jquery.touchSwipe.min.js"></script>
- <script>
- // Fully version: 1.6.3
- if( $("html").hasClass("ie8") || $("html").hasClass("ie7") ) {
- document.open();document.body.innerHTML = '';document.write(html); document.close();
- }else {
- $(window).load(function(){
- initSkin({
- animationInterval: 1000,
- amountImages: 4,
- wrapAround: true,
- fontSize: 13,
- showPhotoDataFromStart: false,
- slideshowInterval: 3,
- opacity: 30,
- });
- });
- }
- </script>
- </body></html>
- '@
- dir . -Include *.jpg, *.png, *.bmp -Recurse|?{$_ -is [IO.FileInfo] -and $_.Directory.Name -ne 'Res'}|group DirectoryName|forEach{
- $n = 0;
- $a = $_.Group | forEach{ '<img src="' + $_.Name + '" data-href="' + $_.Name + '" alt="Photo-'+ ++$n + '">' };
- $s = $str -replace 'MyPhotoFolder', [IO.Path]::GetFileName($_.Name);
- $s = $s -replace '<img src=.*>', ($a -join '');
- $s = $s -replace '(?<=amountImages: )4', $_.Count;
- sc -Path ($_.Name + '\index.html') -Value $s;
- }
- echo 'Done';
- [Console]::ReadKey()
复制代码
作者: xp3000 时间: 2019-9-24 14:18
非常感谢,学习了
作者: xp3000 时间: 2019-9-26 11:21
res文件夹是需要排除的,目录里面没有图片的文件夹也被生成文件了,这个作为本地浏览还是很不错的,图片一个个播放
作者: WHY 时间: 2019-9-28 16:34
回复 5# xp3000
已修改。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |