在codeigniter中裁剪图像时,我一直在搜索许多网站以更改背景颜色,但没有结果。
当我使用image_lib GD2 Codeigniter进行裁剪时,我有一个图像偏移图像背景颜色为黑色这里是图片
如何改变这个? 这是我的代码:
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/thumb/thumb_'.$fileName;
$config['width'] = 200;
$config['height'] = 250;
$config['maintain_ratio'] = FALSE;
$config['x_axis'] = '20';
$config['y_axis'] = '0';
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->crop();
谁能帮帮我?对不起,我的英语很糟糕,谢谢你的回答。
答案 0 :(得分:-1)
这就是我这样做的方式:
public function saveImage($web_id, $user_id, $photo, $index = -1, $path=false, $crop = true, $crop_x = 0, $crop_y = 0, $width = 0, $height = 0)
{
/* Image upload */
$this->ci->load->helper("string");
$this->ci->load->library('upload');
if(!$path)
$path = getcwd().'/assets/img/locations/'.$user_id."/".$web_id;
else
$path = getcwd().$path;
$config['upload_path'] = $path;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name'] = random_string('alpha', 39);
$config['overwrite'] = true;
$this->ci->upload->initialize($config);
if (!$this->ci->upload->do_upload($photo, $index))
{
/*echo "<br>path: ".$config['upload_path']."<br>";
echo "user_id: ".$user_id." web_id: ".$web_id." error: ". $this->ci->upload->display_errors();
die;*/
$photo = '';
}
else{
$image_data = $this->ci->upload->data();
$photo = $image_data['file_name'];
if($crop)
{
$this->ci->load->library('image_lib');
$config = array(
'image_library' => 'gd',
'source_image' => $image_data['full_path'],
'new_image' => $path,
'x_axis' => $crop_x,
'y_axis' => $crop_y,
'width' => $width,
'height' => $height,
'overwrite' => true,
'maintain_ratio' => false
);
$this->ci->image_lib->initialize($config);
if ( ! $this->ci->image_lib->crop())
{
echo $this->ci->image_lib->display_errors();
die;
}
}
}
return $photo;
}
您不需要使用许多内容,但可以将其作为基础使用。
我希望它可以帮到你。