可以在参数中引用图像的宽度和高度吗?

huangapple go评论42阅读模式
英文:

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 &#39;%t&#39; &#39;.\*.jpg&#39; &#39;./%[filename:original]-resized.jpg&#39;

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 &#39;max(%w,%h)xmax(%w,%h)&#39; -extent &#39;max(%w,%h)xmax(%w,%h)&#39; `
# ...

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 &#39;.\*.jpg&#39;.

Then, to do what you want change

-resize &#39;max(%w,%h)xmax(%w,%h)&#39; -extent &#39;max(%w,%h)xmax(%w,%h)&#39;

to

-resize &quot;%[fx:max(w,h)]x%[fx:max(w,h)]&quot; -extent &quot;%[fx:max(w,h)]x%[fx:max(w,h)]&quot;

huangapple
  • 本文由 发表于 2023年2月8日 09:50:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定