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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)