4

こんにちは、ciドキュメントによると、image_libで画像のサイズを変更でき、その画像から追加のサムネイルを作成できることを示唆するオプションがあります

create_thumb    FALSE   TRUE/FALSE (boolean)    Tells the image processing function to create a thumb.  R
thumb_marker    _thumb  None    Specifies the thumbnail indicator. It will be inserted just before the file extension, so mypic.jpg would become mypic_thumb.jpg    R

ここに私のコードがあります

        $config_manip = array(
            'image_library' => 'gd2',
            'source_image'  => "./uploads/avatar/tmp/{$this->input->post('new_val')}",
            'new_image'     => "./uploads/avatar/{$this->input->post('new_val')}",
            'maintain_ratio'=> TRUE ,
            'create_thumb'  => TRUE ,
            'thumb_marker'  => '_thumb' ,
            'width'         => 150,
            'height'        => 150 
        );

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

このコードは画像のサイズを変更し、サムネイルも作成すると思いますが、指定された寸法と _tump 接尾辞を持つ画像は 1 つしか取得できません

このコードを追加して2番目の画像を手動で作成しようとしましたが、それでも機能せず、画像が1つしか取得できません

            $this->image_lib->clear();

$config_manip['new_image'] = 
"./uploads/avatar/thumbnail_{$this->input->post('new_val')}";

            $config_manip['width']     = 30 ;
            $config_manip['height']    = 30 ;
            $this->load->library('image_lib', $config_manip);
            $this->image_lib->resize();
4

4 に答える 4

19

パスがコードの問題のようです。私はそれが機能することを自分で修正してテストしました。

public function do_resize()
{
    $filename = $this->input->post('new_val');
    $source_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/tmp/' . $filename;
    $target_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/';
    $config_manip = array(
        'image_library' => 'gd2',
        'source_image' => $source_path,
        'new_image' => $target_path,
        'maintain_ratio' => TRUE,
        'create_thumb' => TRUE,
        'thumb_marker' => '_thumb',
        'width' => 150,
        'height' => 150
    );
    $this->load->library('image_lib', $config_manip);
    if (!$this->image_lib->resize()) {
        echo $this->image_lib->display_errors();
    }
    // clear //
    $this->image_lib->clear();
}

これがお役に立てば幸いです。ありがとう!!

于 2012-07-16T13:21:38.187 に答える
2

コードは問題ありませんが、小さな変更を行う必要があります。

 $this->load->library('image_lib');
 $this->image_lib->initialize($config_manip);
于 2015-12-31T21:18:17.087 に答える