ImageMagick - 调整到最大宽度

发布于 2024-12-19 10:58:36 字数 102 浏览 0 评论 0原文

我想将图像大小调整为最大宽度。所以我不关心图像的高度,但我只想始终将其大小调整为特定的宽度。

我确信我以前做过这个,只是现在不记得我是怎么做到的了。

I want to resize an image to a max width. So I don't care about the height of the image, but I just want to always resize it to a specific width.

I'm certain I've done this before I just can't remember how I did it now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

£烟消云散 2024-12-26 10:58:36

似乎这就是完成的方式,请注意宽度是第一个参数。

convert -resize '100' image.png

对于其他想知道身高的人,那么您可以这样做:

convert -resize 'x100' image.png

来源:http:// www.imagemagick.org/script/command-line-processing.php

编辑(2014 年 11 月): 请注意,在最新版本的 ImageMagick 中,您不能再在值周围使用引号,因为根据凯文拉贝科特的评论。

Seems this is the way it is done, noting that width is the first parameter.

convert -resize '100' image.png

For anyone else wondering about height, then you would do this:

convert -resize 'x100' image.png

Source: http://www.imagemagick.org/script/command-line-processing.php

Edit (Nov 2014): Note that in the latest versions of ImageMagick you can no longer use quotes around the values as per Kevin Labécot's comment.

始于初秋 2024-12-26 10:58:36

你的问题含糊不清。您的标题要求将图像大小调整为最大宽度,但您似乎说要将图像大小调整为特定宽度。

如果您想将某些内容的最大宽度调整为 600 像素(即,任何宽度小于 600 像素的图像都不会受到影响),请使用:

convert original_image.jpg -resize 600x\> result_image.jpg

或者,直接修改原始图像:

mogrify  -resize 600x\> original_image.jpg

如果您想要最大高度而不是最大宽度:

convert original_image.jpg -resize x600\> result_image.jpg

Your question is ambiguous. Your titles asks to resize an image to a max width, but then you seem to say you want to resize the image to a specific width.

If you want to resize something to a max width of 600px (ie, any image with a width of less than 600px will be unaffected), use:

convert original_image.jpg -resize 600x\> result_image.jpg

Or, to directly modify the original image:

mogrify  -resize 600x\> original_image.jpg

If you'd like max height rather than max width:

convert original_image.jpg -resize x600\> result_image.jpg
年华零落成诗 2024-12-26 10:58:36

您只是通过数学来计算出正确的宽高比吗?

$new_width = 400; // config
$image_width = 480; // loaded from image
$image_height = 786; // loaded from image
$new_height = $new_width * ($image_height / $image_width);
echo "$image_width x $image_height becomes $new_width x $new_height";

Are you just chasing the math to work out the correct aspect ratio?

$new_width = 400; // config
$image_width = 480; // loaded from image
$image_height = 786; // loaded from image
$new_height = $new_width * ($image_height / $image_width);
echo "$image_width x $image_height becomes $new_width x $new_height";
缘字诀 2024-12-26 10:58:36

在 ImageMagick 中调整大小到给定宽度的方法是:

convert image -resize Wx result

or just

convert image -resize W result

where W=width and is provided, but H=height is not included

参见 https://imagemagick .org/script/command-line-processing.php#geometry

The way to resize to a given width in ImageMagick is:

convert image -resize Wx result

or just

convert image -resize W result

where W=width and is provided, but H=height is not included

See https://imagemagick.org/script/command-line-processing.php#geometry

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文