0

我对 codeigniter 很陌生,只是用它构建了我的第一个应用程序,但是在从图像生成缩略图时我有点难过。

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

我希望有人能帮帮我,我可能只是一个山雀,而且它真的很简单,比如错误拼写 var。

这是我的图像模型的代码:

<?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();

        }               

    }
?>
4

2 回答 2

1

我认为您需要将 create_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(); 
} 
于 2012-05-24T20:04:20.553 回答
0

这段代码对我有用。希望它对你有用。您还可以在 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();
    }
于 2012-05-25T15:38:28.773 回答