2017-01-26 18 views
1

フォルダ内の画像のサイズを小さくするスクリプトを作成しようとしています。しかし、私はいつもエラーメッセージがあります。 同じフォルダとサブフォルダのサイズを小さくする必要があります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 

答えて

1

つまりあなたは(私は仮定)を使用している。ここ

はスクリプトです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も変更する必要があります。

+0

ありがとうございました。 イメージ.pngのサイズを小さくすることはできますか?スクリプトの変更により画像拡張子が変更されました。 – pcarrey

+0

申し訳ありません、それは私です、私は$ sourceで間違いを犯しました。 – pcarrey

+0

私は他の問題があります。私は写真付きのフォルダをいくつか除外しなければならないが、パラメータ-excludeは機能しない。私はどうすればいいですか? – pcarrey

0

使用の$ source_photos.fullname

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

回答ありがとう – pcarrey

関連する問題