英文:
Can I refer to the image width and height in an argument?
问题
我想将多张图片转换成正方形格式,将任何空白处填充为黑色。假设图片的宽度为1000,高度小于1000(或者反之),我可以这样做(使用PowerShell):
```powershell
magick.exe convert -background black -gravity center `
-resize 1000x1000 -extent 1000x1000 `
-set filename:original '%t' '*.jpg' './%[filename:original]-resized.jpg'
然而,我希望这也适用于任意大小的图片。我需要做类似这样的事情,但实际上不支持这种语法:
#...
-resize 'max(%w,%h)xmax(%w,%h)' -extent 'max(%w,%h)xmax(%w,%h)' `
# ...
有没有Imagemagick支持我所尝试做的这个操作的语法?
<details>
<summary>英文:</summary>
I want to convert multiple images into square format, filling any empty space with black. Assuming the images have a width of 1000 and a height of less than 1000 (or vice versa), I can do it like this (using PowerShell):
```powershell
magick.exe convert -background black -gravity center `
-resize 1000x1000 -extent 1000x1000 `
-set filename:original '%t' '.\*.jpg' './%[filename:original]-resized.jpg'
However, I want this to work for arbitrarily sized images. I need to do something like this, which is not an actually supported syntax:
#...
-resize 'max(%w,%h)xmax(%w,%h)' -extent 'max(%w,%h)xmax(%w,%h)' `
# ...
Is there an Imagemagick syntax for what I'm trying to do?
答案1
得分: 1
在Imagemagick 7中,使用magick
而不是magick convert
,并将输入参数移到第一个参数位置,即magick '.\*.jpg'
。
然后,要执行你想要的更改:
-resize '%[fx:max(w,h)]x%[fx:max(w,h)]' -extent '%[fx:max(w,h)]x%[fx:max(w,h)]'
变成:
-resize "%[fx:max(w,h)]x%[fx:max(w,h)]" -extent "%[fx:max(w,h)]x%[fx:max(w,h)]"
英文:
In Imagemagick 7, use magick
, not magick convert
and move the input parameter to the first parameter position, i.e. magick '.\*.jpg'
.
Then, to do what you want change
-resize 'max(%w,%h)xmax(%w,%h)' -extent 'max(%w,%h)xmax(%w,%h)'
to
-resize "%[fx:max(w,h)]x%[fx:max(w,h)]" -extent "%[fx:max(w,h)]x%[fx:max(w,h)]"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论