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 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同