doutan5844
2018-07-03 13:59
浏览 34
已采纳

如何在CodeIgniter中使用php翻转图像

I am trying to do flip operation in CodeIgniter I have found a code for image flip in php using codeigniter libraries First I uploaded image to a path, here is the coding of controller for this purpose:

$config['upload_path'] = 'D:/xampp/htdocs/ImageTools/assets/images/pages/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->image_lib->clear();
$this->load->library('upload',$config);
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image='noimage.jpg';
}else{
$file_data = $this->upload->data();
$data['img'] = base_url().'assets/images/pages/'.$file_data['file_name'];
$this->load->view('pages/inverted',$data);

I tried to do the invert operation here but couldn't succeeded then tried to invert the uploaded image, done the coding in view file by passing this uploaded image to view:

<?php $img;?>
<?php
$this->image_lib->clear();
$config=array();
$config['image_library'] = 'gd2';
$config['source_image'] = $img;
$config['create_thumb'] = TRUE;
$config['rotation_angle'] = 'hor';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->load->library('upload',$config);
$this->image_lib->rotate();                    
if ( ! $this->image_lib->rotate())
{
echo $this->image_lib->display_errors();
}
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image='noimage.jpg';
}
else{
$file_data = $this->upload->data();
$data = base_url().'/assets/images/pages/'.$file_data['file_name'];
}              
?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dounaidu0204 2018-07-04 19:23
    已采纳

    First off D:/xampp/htdocs/ImageTools/assets/images/pages/ will never be valid in a server environment. There is a way to make it valid for all environments like so:

    $config['upload_path'] = './ImageTools/assets/images/pages/';

    (there are other ways but this is the one in the CI docs)

    If the folder ImageTools is actually imagetools then that needs to be used in the above example; Linux is case sensitive.

    Therefore, following the docs, you can do:

    $upload['upload_path'] = './ImageTools/assets/images/pages/';
    $upload['allowed_types'] = 'gif|jpg|png';
    
    $this->load->library('upload', $upload);
    
    if (!$this->upload->do_upload('userfile')) {
        show_error($this->upload->display_errors());
    }
    
    $this->load->library('image_lib');
    
    $config['image_library'] = 'gd2';
    $config['source_image'] = $this->upload->data('full_path');
    $config['rotation_angle'] = 'hor'; // or whatever
    
    $this->image_lib->initialize($config);
    
    if (!$this->image_lib->rotate()) {
        show_error($this->image_lib->display_errors());
    }
    
    $img_path = base_url() . '/assets/images/pages/' . $this->upload->data('file_name');
    
    echo "<img src='{$img_path}' width='auto' height='200'>";
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题