Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中生成图像拇指_Php_Codeigniter - Fatal编程技术网

Php 在codeigniter中生成图像拇指

Php 在codeigniter中生成图像拇指,php,codeigniter,Php,Codeigniter,我对codeigniter还很陌生,刚刚用它构建了我的第一个应用程序,但当涉及到从图像生成缩略图时,我有点不知所措 图像上传正确,但拇指未生成,我没有收到任何错误:( 我希望有人能帮我一把,很可能我只是一只山雀,这真的很简单,比如拼写错误 以下是我的图像模型的代码: <?php class Image_model extends CI_Model { var $image_path; function Image_model(){

我对codeigniter还很陌生,刚刚用它构建了我的第一个应用程序,但当涉及到从图像生成缩略图时,我有点不知所措

图像上传正确,但拇指未生成,我没有收到任何错误:(

我希望有人能帮我一把,很可能我只是一只山雀,这真的很简单,比如拼写错误

以下是我的图像模型的代码:

<?php

class Image_model extends CI_Model {

        var $image_path;

        function Image_model(){

            parent::__construct();

            $this->image_path = realpath(APPPATH.'../'.$this->config->item('dir_dynamic_images'));

        }

        function do_upload(){

            $config = array(
                    'allowed_types' => "jpeg|gif|jpg|png",
                    'upload_path' => $this->image_path,
                    'max_size' => 2000
            );

            $this->load->library('upload', $config);

            $this->upload->do_upload();
            $image_data = $this->upload->data();



            $config = array(
                'source_image' => $image_data['full_path'],
                'new_image' => $this->image_path . '/thumbs',
                'maintain_ratio' => true,
                'width' => 200,
                'height' => 200
            );

            echo $config['new_image'];

            $this->load->library('image_lib', $config);
            $this->image_lib->resize();

        }               

    }
?>

我认为您需要将create\u thumb参数设置为true,并指定图像库-

 $config = array(
                'image_library' => 'gd2',
                'source_image' => $image_data['full_path'],
                'create_thumb' => true,
                'new_image' => $this->image_path . '/thumbs',
                'maintain_ratio' => true,
                'width' => 200,
                'height' => 200
            );
尝试使用以下命令查找错误-

if(!$this->image_lib->resize()) 
{ 
   echo $this->image_lib->display_errors(); 
} 

这段代码对我有用。希望它对你有用。你也可以检查codeigniter中的图像处理助手。别忘了初始化配置

 $config['image_library'] = 'imagemagick';
    $config['library_path'] = '/usr/X11R6/bin/';
    $config['source_image'] = '/path/to/image/mypic.jpg';
    $config['x_axis'] = '100';
    $config['y_axis'] = '60';

    $this->image_lib->initialize($config);

    if ( ! $this->image_lib->crop())
    {
        echo $this->image_lib->display_errors();
    }

可能是权限问题…检查日志我已检查了错误日志,但没有显示任何内容。请尝试指定图像库(我已编辑了答案)。尝试查找与此相关的任何错误-if(!$this->image_lib->resize()){echo$this->image_lib->display_errors();}啊哈,宾果(感谢大家对dispay_errors函数的介绍,这将派上用场)我收到以下错误:您的服务器不支持处理此类图像所需的GD函数。不支持PNG图像。看起来我必须更改一些服务器设置。感谢您的帮助。错误消息在这里有误导性。我不认为您的服务器没有GD库。请尝试指定的名称新建图像参数中的缩略图->'new\u image'=>$this->image\u path./thumbs/test.jpg'我实际上没有在服务器上安装GD功能。我刚刚检查过。感谢您的帮助