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

如何在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'>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档