调整图像大小以完全适合尺寸(Codeigniter)

发布于 2024-11-18 17:02:06 字数 218 浏览 2 评论 0原文

我正在使用 Codeigniter 中的图像库来调整图像大小。我注意到 CI 只调整图像大小以适合指定尺寸:调整大小以适合 30px x 20px 框的 50px x 50px 图像将调整为 20px x 20px 大小,并为空白区域留下黑色区域。

我想要的是调整大小,使调整大小的图像填充整个 30px x 30px 的空间,多余的部分被裁剪掉。

这在 Codeigniter 中可能吗?

I am using the image library in Codeigniter to resize my image. I notice that CI only resizes the image to fit inside the specified dimensions: A 50px by 50px image resized to fit a 30px by 20px box will be resized to 20px by 20px and leaves a black area for the empty space.

What I want is to resize such that the resize image fills the entire 30px by 30px space with the excess portion being cropped out.

Is this possible in Codeigniter?

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

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

发布评论

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

评论(1

究竟谁懂我的在乎 2024-11-25 17:02:06

我认为您需要首先调整图像大小,选择宽度或高度作为“主”尺寸,然后裁剪它。

我还没有测试过这段代码,但请尝试一下。如果不出意外的话,它应该能给你一个想法。

$config['source_image'] = '/path/to/image/mypic.jpg';

$config['width'] = 30;
$config['height'] = 0; // No restraint on height
$this->load->library('image_lib', $config);
$this->image_lib->resize();

$config['x_axis'] = 30; // Same width as before
$config['y_axis'] = 20; // Crop to height
$this->image_lib->initialize($config);
$this->image_lib->crop();

您可能想尝试将裁剪尺寸居中。无论您选择哪种方式,图像都需要在某个时刻进行裁剪。

我应该注意到,我不确定 $config['height'] = 0 是否是忽略高度的正确方法,它可能必须是 FALSE,一个真正的高数字,或完全删除(有一段时间没有使用 CI 图像库)。

I think you'll need to resize the image first, choosing either width or height as the "master" dimension, then crop it.

I haven't tested this code, but give it a shot. If nothing else, it should give you the idea.

$config['source_image'] = '/path/to/image/mypic.jpg';

$config['width'] = 30;
$config['height'] = 0; // No restraint on height
$this->load->library('image_lib', $config);
$this->image_lib->resize();

$config['x_axis'] = 30; // Same width as before
$config['y_axis'] = 20; // Crop to height
$this->image_lib->initialize($config);
$this->image_lib->crop();

You may want to try to center the crop dimensions instead. Whichever way you choose to do it, the image needs to be cropped at some point.

I should note that I'm not sure if $config['height'] = 0 is the right way to ignore height, it might have to be FALSE, a really high number, or removed altogether (haven't worked with the CI image lib in a while).

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