首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell -减小图像的大小

PowerShell -减小图像的大小
EN

Stack Overflow用户
提问于 2017-01-26 18:46:32
回答 2查看 8.5K关注 0票数 1

我尝试编写一个脚本来减小文件夹中图像的大小。但是我总是有一个错误信息。我必须减小相同文件夹和子文件夹中的大小

你可以帮助建立我的脚本吗?

提前谢谢你。

下面是脚本:

代码语言:javascript
复制
$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

}

下面是错误消息:

代码语言:javascript
复制
    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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-26 18:56:03

您正在使用(我假设) Resize-Image模块。

报告的问题是不支持路径的文件格式。

如果没有进一步的数据,我假设您正在向OutputFile传递一个完整的对象。要解决此问题,请尝试指定Name属性。

代码语言:javascript
复制
$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也应该更改。

票数 5
EN

Stack Overflow用户

发布于 2017-01-26 18:54:57

使用$source_photos.fullname,即

代码语言:javascript
复制
... Resize-Image -InputFile $($source_photos.fullname) -Scale ....
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41871756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档