我尝试编写一个脚本来减小文件夹中图像的大小。但是我总是有一个错误信息。我必须减小相同文件夹和子文件夹中的大小
你可以帮助建立我的脚本吗?
提前谢谢你。
下面是脚本:
$source = "U:\TEST\Compression\images"
$exclude_list = "(Imprimerie|Photos)"
$source_listephotos = Get-ChildItem $source -Recurse | where {$_.FullName -notmatch $exclude_list}
foreach ( $source_photos in $source_listephotos ) {
$source_photos
Resize-Image -InputFile $source_photos.FullName -Scale 30 -OutputFile (Join-Path $source $source_photos.Name) -Verbose
}下面是错误消息:
Exception calling "Save" with "1" argument(s): "A generic error occurred in GDI+."
At C:\windows\system32\windowspowershell\v1.0\Modules\Resize-Image\Resize-Image.psm1:70 char:9
+ $img2.Save($OutputFile);
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ExternalException发布于 2017-01-26 18:56:03
您正在使用(我假设) Resize-Image模块。
报告的问题是不支持路径的文件格式。
如果没有进一步的数据,我假设您正在向OutputFile传递一个完整的对象。要解决此问题,请尝试指定Name属性。
$source = "U:\TEST\Compression\images"
$destination = "U:\TEST\Compression\image_resizer"
$exclude_list = @("*Imprimerie","*Photos*")
$source_listephotos = Get-ChildItem $source -Exclude $exclude_list -Recurse
foreach ( $source_photos in $source_listephotos ) {
Resize-Image -InputFile $source_photos.FullName -Scale 30 -OutputFile (Join-Path $destination $source_photos.Name) -Verbose
}正如另一个答案所提到的,InputFile也应该更改。
发布于 2017-01-26 18:54:57
使用$source_photos.fullname,即
... Resize-Image -InputFile $($source_photos.fullname) -Scale ....https://stackoverflow.com/questions/41871756
复制相似问题