CodeIgniter 图像裁剪 - 图像不受 Crop() 参数影响
的用户图像
function crop_avatar()
{
$id = $this->tank_auth->get_user_id();
//get current avatar
$query = $this->db->get_where('user_profiles', array('id' => $id));
foreach ($query->result() as $row) {
$j[$row->avatar] = $row->avatar;
}
$config['image_library'] = 'gd';
$config['source_image'] = '.' . substr("$row->avatar", 18);
$config['x_axis'] = '10';
$config['y_axis'] = '60';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
if ( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}
// print_r($config);
}
我有这个模型来裁剪生成此数组
Array
(
[image_library] => gd
[source_image] => ./images/avatars/b0b623057.jpg
[x_axis] => 10
[y_axis] => 60
)
(通过 print_r) ,出于某种我不知道的原因 - 没有进行裁剪。原始图像直接通过该模型,并且没有改变。
我的服务器上确实有 GD——你知道这里可能出了什么问题吗?
非常感谢。
I have this model to crop the user's image
function crop_avatar()
{
$id = $this->tank_auth->get_user_id();
//get current avatar
$query = $this->db->get_where('user_profiles', array('id' => $id));
foreach ($query->result() as $row) {
$j[$row->avatar] = $row->avatar;
}
$config['image_library'] = 'gd';
$config['source_image'] = '.' . substr("$row->avatar", 18);
$config['x_axis'] = '10';
$config['y_axis'] = '60';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
if ( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}
// print_r($config);
}
which generates this array (via print_r)
Array
(
[image_library] => gd
[source_image] => ./images/avatars/b0b623057.jpg
[x_axis] => 10
[y_axis] => 60
)
For some reason unknown to me - there's no cropping going on. The original image passes straight thru this model, and is unchanged.
I do have GD on my server -- any ideas what might be wrong here?
Thanks a ton.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要定义要裁剪图像的宽度和高度。
x_axis
和y_axis
配置值是现有图像中应开始裁剪的点。换句话说,您需要 4 个测量值来裁剪图像:垂直开始位置 (
y_axis
)、水平开始位置 (x_axis
)、垂直结束位置 (x_axis
)高度
)和水平结束位置(宽度
)如果裁剪图像的尺寸之一与原始图像的尺寸相同,请不要忘记设置 <代码>maintain_ratio到
假
You need to define the width and height you want your image to be cropped at.
The
x_axis
andy_axis
config values are the point in your existing image where the crop should start.To put it another way, you need 4 measurements to crop the image : where to start vertically (
y_axis
), where to start horizontally (x_axis
), where to end vertically (height
) and where to end horizontally (width
)If one of the dimensions of your cropped image is the same as that of your original image, don't forget to set
maintain_ratio
tofalse