找到按比例调整大小的暗淡,该暗淡应小于或等于所需的拇指暗淡

发布于 2024-09-26 10:44:27 字数 242 浏览 3 评论 0原文

我的 php 需要调整图像大小,以便调整大小后的宽度和高度应小于或等于预期的调整大小值。

考虑源图像是 680x520

所需的缩略图大小应 <= 300x200

我想找到调整大小的比例值,该值应小于或等于 300x200。

它可以是 299x199 或 300x200,但宽度不超过 300,高度不超过 200。

所以两者都应该小于或等于所需的大小。

公式可能是什么?

I php need to resize an image so that both width and height after resize should be less than or equal to the expected resized values.

consider the source image is 680x520

The needed thumbmail size should be <= 300x200

I want to find the resized proportional value which should be less than or equal to 300x200.

it can be like 299x199 or 300x200 but not greater than 300 in width and 200 in height.

So both should be less than or equal to the needed size.

What could be the formula?

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

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

发布评论

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

评论(2

虫児飞 2024-10-03 10:44:27
//height - original image height;
//width  - original image width;
if ($height > $width) {
  $thumb_height = 200;
  $thumb_width = round(($width * $thumb_height) / $height);
} else {
  $thumb_width = 300;
  $thumb_height = round(($height * $thumb_width) / $width);
}

编辑:

//height - original image height;
//width  - original image width;
$thumb_height = 0;
$thumb_width  = 0;
if ($height > $width) {
    $thumb_height = 200;
} else {
  if ($height > ($width * 200)/300)
    $thumb_height = 200;
  else
    $thumb_width  = 300;
}

if ($thumb_height > 0) {
  $thumb_width = round(($width * $thumb_height) / $height);
} else {
  $thumb_height = round(($height * $thumb_width) / $width);
}

我没有找到你给我的相反的任何例子。如果您有的话,请告诉我,我会检查上面的脚本是否需要任何修改。

//height - original image height;
//width  - original image width;
if ($height > $width) {
  $thumb_height = 200;
  $thumb_width = round(($width * $thumb_height) / $height);
} else {
  $thumb_width = 300;
  $thumb_height = round(($height * $thumb_width) / $width);
}

EDIT:

//height - original image height;
//width  - original image width;
$thumb_height = 0;
$thumb_width  = 0;
if ($height > $width) {
    $thumb_height = 200;
} else {
  if ($height > ($width * 200)/300)
    $thumb_height = 200;
  else
    $thumb_width  = 300;
}

if ($thumb_height > 0) {
  $thumb_width = round(($width * $thumb_height) / $height);
} else {
  $thumb_height = round(($height * $thumb_width) / $width);
}

I didn't find any example for the reversed that you gave me. If you have one, please tell me and I will check to see if the above script needs any modifications.

冰雪之触 2024-10-03 10:44:27

也许离题了,但是对于图像处理来说确实很容易使用:
宽图像

Maybe offtopic, but for image manipulation realy easy to use:
Wide Image

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