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

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因