我一直在使用Dreamweaver CC并建立了一个偏离this one偏离的jssor图像库,它看起来效果很好。但现在我正在尝试将所有图像和缩略图添加到每个图库中,并且找不到将它们大量添加的好方法。所有图像和缩略图都在单独的文件夹中以编号顺序排列。以下示例。
<div>
<img u="image" src="../../Images/Gallery/Engagement/image/_MG_0870_1001.JPG" />
<img u="thumb" src="../../Images/Gallery/Engagement/thumb_BnW/_MG_0870_1001.jpg" />
</div>
<div>
<img u="image" src="../../Images/Gallery/Engagement/image/_MG_0886_1002.JPG" />
<img u="thumb" src="../../Images/Gallery/Engagement/thumb_BnW/_MG_0886_1002.jpg" />
</div>
我无法在Dreamweaver中找到一种方法,所以尝试在PowerShell中编写一些东西,我可以接近但不是所有的方法都无济于事。
$images = Get-ChildItem -Path "G:\Personal\Images\Gallery\1\image\"
$thumb_bnw = Get-ChildItem -Path "G:\Personal\Images\Gallery\1\thumb_BnW\"
# enumerate the items array
ForEach ($item in $images)
{
$img=$item.Name
Write-Host "<div>"
Write-Host $img
Foreach ($thumb_b in $thumb_bnw)
{
$bnw=$thumb_b.Name
Write-Host $bnw
Write-Host "</div>"
}
}
答案 0 :(得分:0)
实施例; 请写当前目录图像(../../Images/Gallery/Engagement/image/)和(../../ Images / Gallery / Engagement / thumb_BnW /)
<?php
$image = glob('../../Images/Gallery/Engagement/image/*.jpg');
$thumb = glob('../../Images/Gallery/Engagement/thumb_BnW/*.jpg');
$image = array_chunk($image, 1);
$thumb = array_chunk($thumb, 1);
foreach ($image as $key => $img) {
echo '<div>
<img u="image" src="../../Images/Gallery/Engagement/image/'.$img[0].'" />
<img u="thumb" src="../../Images/Gallery/Engagement/thumb_BnW/'.$thumb[$key][0].'" />
</div>';
}
?>
索里,我的英语不好。
答案 1 :(得分:0)
所以你只是想尝试自动创建一些HTML代码。首先,两个文件名看起来都是一样的,所以为什么还要在第二个循环中再次收集数据。我们也可以使用here-string来帮助格式化。
$template = @"
<div>
<img u="image" src="../../Images/Gallery/Engagement/image/{0}" />
<img u="thumb" src="../../Images/Gallery/Engagement/thumb_BnW/{0}" />
</div>
"@
$imagePath = "C:\Users\Public\Pictures\Sample Pictures"
Get-ChildItem $imagePath -Filter "*.jpg" | ForEach-Object{
$template -f $_.Name
}
这将吐出格式化的html代码,其中文件名被插入到正确的位置。
<div>
<img u="image" src="../../Images/Gallery/Engagement/image/Penguins.jpg" />
<img u="thumb" src="../../Images/Gallery/Engagement/thumb_BnW/Penguins.jpg" />
</div>
<div>
<img u="image" src="../../Images/Gallery/Engagement/image/Tulips.jpg" />
<img u="thumb" src="../../Images/Gallery/Engagement/thumb_BnW/Tulips.jpg" />
</div>