Powershell:删除特定尺寸的图像 [英] Powershell: Delete images of certain dimensions

查看:43
本文介绍了Powershell:删除特定尺寸的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除特定文件夹中的所有* .jpg文件及其所有子文件夹,例如宽度不等于800和高度不等于600(仅保留800x600 jpg图像).

I want to delete all *.jpg files in a specific folder and all its subfolders which have e.g. width unequal 800 and height unequal 600 (leaving only 800x600 jpg images).

有人可以告诉我如何在Powershell中执行此操作吗?

Can someone tell me how to do this in Powershell?

我知道我可以删除* .jpg图片

I know I can remove *.jpg images with

Get-ChildItem -Path .\ -Filter *.jpg -Recurse | foreach ($_) {remove-item $_.fullname}

但是我似乎找不到如何选择图像的高度/宽度.

But I can't seem to find how to select height/width of an image.

推荐答案

您可以使用 System.Drawing.Image .NET对象:

You could use the System.Drawing.Image .NET Object:

$(Get-ChildItem -Filter *.jpg).FullName | ForEach-Object { 
    $img = [Drawing.Image]::FromFile($_); 
    $dimensions = "$($img.Width) x $($img.Height)"

    If ($dimensions -eq "800 x 600") {
        Remove-Item $_
    }
}

这篇关于Powershell:删除特定尺寸的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆