问题描述
我在一个文件夹中获得了 1000 张图片 &我想调整大小 &每张打印 12 到 24 个图像.使用 BATCH 脚本从文件夹中收集图像并输出带有 3 列的 HTML 脚本.每页 6 行,在 Firefox 中打开(缩小以适应和打印).
如何在 html 脚本的每个图像上添加文件名、日期.
del "c:zz.html"setlocal EnableDelayedExpansion设置/a "p=1"设置/a "m=2"设置/a "w=4"echo ^<table cellspacing="5" style="border:1px纯黑色;"^>>>"c:zz.html"for/f "delims=" %%i in ('dir/s/b/a-d f:jpegmdl*.jpg') 做 (设置/a "p=p+1"回声!p!如果!p!==!米!(设置 "bo=")如果!p!== !w!(设置p=1"设置 "bo=")echo !bo!^<td^>^<img width=320 height=260 src="file:\%%i"^>>>"c:zz.html")启动 C:Program FilesMozilla Firefoxfirefox.exe "c:zz.html" &exit
这是可用的代码
del "c:zz.html"setlocal EnableDelayedExpansion设置/a "p=1"设置/a "m=2"设置/a "w=4"echo ^<table cellspacing="5" style="border:1px纯黑色;"^>>>"c:zz.html"对于/f "delims=" %%i in ( 'dir/s/b/a-d %1*.*' ) 做 (回声 %1设置/a "p=p+1"回声!p!如果!p!==!米!(设置 "bo=")如果!p!== !w!(设置p=1"设置 "bo=")echo !bo!^<td^>^<img width=320 height=260 src="file:\%%i"^>^<br^>%%~nxi >>"c:zz.html")开始 I:HEVCm-ozm.f -no-remote -profile "I:HEVCm-ozy" "c:zz.html" &exit
此注册表项提供右键单击以打印任何文件夹.(随意更改源文件夹)
Windows 注册表编辑器 5.00 版[HKEY_CLASSES_ROOTDirectoryshell==jam==j]@="打印===ALL=IN=1=="[HKEY_CLASSES_ROOTDirectoryshell==jam==jCommand]@="I:\s\PPP_Print\p.cmd "%1""
我知道您在开始项目时付出了一些努力,但您似乎需要很多帮助.感谢您分享迄今为止的进展.我想这让你值得一份圣诞礼物.:)
我看到您的问题有几个组成部分.
1.我想调整大小 &每张打印 12 到 24 张图像.
选择一个.你想要12还是24?如果您希望数字根据您打印的图像的高度而变化,那么您最好按照上面的建议调查 Imagemagick.
2.使用 BATCH 脚本从文件夹中收集图像并输出带有 3 列 & 的 HTML 脚本每页 6 行
3 * 6 = 18.让我们继续.一个 8.5x11"页面将处理超过 900 像素的高度,因此将表格单元格的高度设置为 150 像素.(150 * 6 = 900.)
3.在 Firefox 中打开(缩小以适应和打印)
您可以通过包含一些 JavaScript 来调用 window.print();
来触发打印对话框.您仍然需要点击打印".
4.如何在 html 脚本上的每个图像上添加文件名、日期.
假设 %%I
是分配用于在 for
循环中捕获文件名的变量.要获取文件的 basename.ext
,请使用 %%~nxI
.要获取文件的上次修改日期和时间,请使用 %%~tI
.有关此语法的更多信息,请参阅控制台窗口中 help for
的最后两页.
在文本和图像上使用 CSS position: absolute
,在包含它们的 td
元素上使用 position:relative
.或者,您可以将图像加载为背景图像,并在顶部显示内联文本.这需要您将 Firefox 配置为打印背景图像,但可能未配置.
要将 18 个图像放在一个页面上,请一次循环遍历图像文件 18 个,然后在找到第 18 个图像后生成一个 HTML 表格.在您的 CSS 中添加一个 @media print
声明以确保每个表格在打印时触发分页符.要生成您的 HTML,我建议使用 "设置/a 计数+=1)调用 :heredoc 表 >>%htmlfile%";&&转到 end_table<表格单元格间距=5"><tr><td>!img1!!desc1!</td><td>!img2!!desc2!</td><td>!img3!!desc3!</td></tr><tr><td>!img4!!desc4!</td><td>!img5!!desc5!</td><td>!img6!!desc6!</td></tr><tr><td>!img7!!desc7!</td><td>!img8!!desc8!</td><td>!img9!!desc9!</td></tr><tr><td>!img10!!desc10!</td><td>!img11!!desc11!</td><td>!img12!!desc12!</td></tr><tr><td>!img13!!desc13!</td><td>!img14!!desc14!</td><td>!img15!!desc15!</td></tr><tr><td>!img16!!desc16!</td><td>!img17!!desc17!</td><td>!img18!!desc18!</td></tr>:茶几本地端转到:EOF:: https://stackoverflow.com/a/15032476/1683264:heredoc 设置本地启用延迟扩展设置去=对于/f delims="%%A in ('findstr/n "^" "%~f0"') 做 (设置行=%%A"&&设置 "line=!line:*:=!";如果定义了 go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)if "!line:~0,13!"=="call :heredoc";(对于/f "tokens=3 delims=>^";%%i in ("!line!") do (如果#%%i==#%1 (对于/f tokens=2 delims=&"%%I in ("!line!") do (对于/f "tokens=2";%%x in ("%%I") do set "go=%%x")))))转到:EOF
I got 1000's of images on a folder & I wanna resize & print 12 to 24 images per sheet.Using BATCH script to collect images from a folder and output an HTML script with 3 colums & 6 rows per page , open in firefox (shrink to fit &print) .
del "c:zz.html"
setlocal EnableDelayedExpansion
set /a "p=1"
set /a "m=2"
set /a "w=4"
echo ^<table cellspacing="5" style="border:1px solid black;"^> >>"c:zz.html"
for /f "delims=" %%i in ('dir /s/b /a-d f:jpegmdl*.jpg') do (
set /a "p=p+1"
echo !p!
if !p! == !m! (
set "bo=")
if !p! == !w! (
set "p=1"
set "bo=<tr>")
echo !bo!^<td^>^<img width=320 height=260 src="file:\%%i"^> >>"c:zz.html"
)
start C:Program FilesMozilla Firefoxfirefox.exe "c:zz.html" &exit
Here is the usable code
del "c:zz.html"
setlocal EnableDelayedExpansion
set /a "p=1"
set /a "m=2"
set /a "w=4"
echo ^<table cellspacing="5" style="border:1px solid black;"^> >>"c:zz.html"
for /f "delims=" %%i in ( 'dir /s/b /a-d %1*.*' ) do (
echo %1
set /a "p=p+1"
echo !p!
if !p! == !m! (
set "bo=")
if !p! == !w! (
set "p=1"
set "bo=<tr>")
echo !bo!^<td^>^<img width=320 height=260 src="file:\%%i"^>^<br^>%%~nxi >>"c:zz.html"
)
start I:HEVCm-ozm.f -no-remote -profile "I:HEVCm-ozy" "c:zz.html" &exit
This reg key provide Right-Click to print any folder. (change the source folder as you like)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryshell==jam==j]
@="Print===ALL=IN=1=="
[HKEY_CLASSES_ROOTDirectoryshell==jam==jCommand]
@="I:\s\PPP_Print\p.cmd "%1""
I recognize that you put a bit of effort into starting your project, but you appear to need lots of help. I appreciate your sharing your progress thusfar. I guess this makes you worthy of a Christmas present. :)
Your question has several component questions that I see.
Pick one. Do you want 12 or 24? If you want the number to be variable based on the height of the images you're printing, you'd probably be better off investigating Imagemagick as suggested above.
3 * 6 = 18. Let's go with that. An 8.5"x11" page will handle a bit over 900px of height, so set the height of your table cells to 150px. (150 * 6 = 900.)
You can trigger the print dialog by including a bit of JavaScript to call window.print();
. You still have to click "Print".
Assume %%I
is the variable assigned to capture filenames in your for
loop. To get the basename.ext
of a file, use %%~nxI
. To get the file's last modified date and time, use %%~tI
. See the last two pages of help for
in a console window for more information on this syntax.
Use CSS position: absolute
on both your text and your images, and position: relative
on the td
elements containing them. Either that, or you can load your images as background images and just display the text inline on top. This requires you to configure Firefox to print background images, which might not be configured, though.
To put 18 images on a page, loop through your image files 18 at a time, then generate an HTML table once the 18th image is found. In your CSS add a @media print
declaration to ensure each table triggers a page break when printed. To generate your HTML, I suggest that it'd make your code a little more readable and easier to maintain, to employ a batch heredoc function.
Merry Christmas!
@echo off
setlocal enabledelayedexpansion
:: thumbnails.bat
:: generates print layout of *.jpg in current folder
:: https://stackoverflow.com/a/27652107/1683264
set "htmlfile=out.html"
call :heredoc head >"%htmlfile%" && goto end_head
<^!doctype "html">
<html>
<head>
<style type="text/css">
a { text-decoration: none; }
img {
max-width: 200px;
max-height: 150px;
position: absolute;
left: 0px;
bottom: 0px;
}
td {
border: 1px solid black;
position: relative;
width: 200px;
height: 150px;
}
span {
position: absolute;
left: 5px;
top: 5px;
color: purple;
font-family: "Times New Roman";
font-size: 11px;
background: rgba(255, 255, 255, 0.6);
top: 3px;
left: 3px;
}
@media print {
table { page-break-after: always; }
}
</style>
<script type="text/javascript">
addEventListener('load', function() { window.print(); }, false);
</script>
</head>
<body>
:end_head
set count=1
set images=
for %%I in (*.jpg) do (
set images=!images! "%%~fI"
if !count! equ 18 (
call :build_table !images:~1!
set images=
set count=0
)
set /a count+=1
)
if %count% gtr 1 call :build_table !images:~1!
call :heredoc body >>"%htmlfile%" && goto end_body
</body>
</html>
:end_body
start "" "firefox" -new-tab "file:///%CD:=/%/%htmlfile%"
:: End of main script
goto :EOF
:build_table <img1> <img2> ... <img18>
setlocal enabledelayedexpansion
set count=1
for %%I in (%*) do (
set "src=%%~I"
set "img!count!=<a href="file:///!src:=/!"><img src="file:///!src:=/!" />"
set "desc!count!=<span>%%~nxI<br />%%~tI</span></a>"
set /a count+=1
)
call :heredoc table >>"%htmlfile%" && goto end_table
<table cellspacing="5">
<tr>
<td>!img1!!desc1!</td>
<td>!img2!!desc2!</td>
<td>!img3!!desc3!</td>
</tr>
<tr>
<td>!img4!!desc4!</td>
<td>!img5!!desc5!</td>
<td>!img6!!desc6!</td>
</tr>
<tr>
<td>!img7!!desc7!</td>
<td>!img8!!desc8!</td>
<td>!img9!!desc9!</td>
</tr>
<tr>
<td>!img10!!desc10!</td>
<td>!img11!!desc11!</td>
<td>!img12!!desc12!</td>
</tr>
<tr>
<td>!img13!!desc13!</td>
<td>!img14!!desc14!</td>
<td>!img15!!desc15!</td>
</tr>
<tr>
<td>!img16!!desc16!</td>
<td>!img17!!desc17!</td>
<td>!img18!!desc18!</td>
</tr>
</table>
:end_table
endlocal
goto :EOF
:: https://stackoverflow.com/a/15032476/1683264
:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
set "line=%%A" && set "line=!line:*:=!"
if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
if "!line:~0,13!"=="call :heredoc" (
for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
if #%%i==#%1 (
for /f "tokens=2 delims=&" %%I in ("!line!") do (
for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
)
)
)
)
)
goto :EOF
这篇关于在单张纸上批量打印多幅图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!