PowerShell - 减小图像的大小

时间:2017-01-26 10:46:32

标签: powershell

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

请帮忙构建我的脚本吗?

提前谢谢。

这是脚本:

$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

2 个答案:

答案 0 :(得分:3)

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

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

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

$('#add_argument_link').on('click', function(e) {
    // prevent the link from creating a "#" on the URL
    e.preventDefault();

    // setup an "add a argument" link
    var $newLinkLi = $('<li></li>');

    // add a new argument form (see next code block)
    addArgumentForm($collectionHolder, $newLinkLi);
    addTagFormDeleteLink($newLinkLi);
});

正如其他答案所述,还应该更改InputFile。

答案 1 :(得分:1)

使用$ source_photos.fullname,即。

... Resize-Image -InputFile $($source_photos.fullname) -Scale ....