Pertanyaan CodeIgniter Masalah gambar thumbnail


Saya ingin membuat dua thumbnail dengan ukuran yang berbeda dengan dua fungsi. uploadImage ()  membuat thumbnail besar saat uploadIhumb ($ name) {ini memanggil fungsi pertama} membuat thumbnail kecil. FUNGSI PERTAMA MENCIPTAKAN THUMBNAIL TAPI KEDUA TIDAK BEKERJA. tolong selesaikan masalah dan soroti di mana masalah terjadi?

enter code here:
function uploadImage()
        {
                                    $imageName2=$_FILES['file']['tmp_name'];


                $config['image_library'] = 'gd2';
                //$config['source_image']   = $imageName2;// this is temporary folder where image place on uploading time
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = false;
                $config['width']     = 696;
                $config['height']   = 241;
                $config['new_image'] = 'images/uploads';
                $this->load->library('image_lib', $config); 
                $this->image_lib->resize();
                $file_name= basename( $imageName2, ".tmp");
                $filename=$file_name.'_thumb.tmp'; 


        ////////////////////Rename code///////////////////////////
                $name= $this->rand_string( 6 );

                $dir=$_SERVER['DOCUMENT_ROOT'].'/images/uploads/';

                rename($dir . $filename, $dir . $name);
                echo $name;
                $this->uploadIhumb($name); //FUNCTION CALL
}

function uploadIhumb($name)
    {

                $config['image_library'] = 'gd2';
                $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/uploads/'.$name;
                $config['create_thumb'] = TRUE;

                $config['width']     = 80;
                $config['height']   = 80;
                $config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'images/uploads/thumbs/';
                $this->load->library('image_lib', $config); 
                $this->image_lib->resize();


}

4
2017-08-01 04:56


asal


Jawaban:


Tidak Perlu perpustakaan lain yang diperlukan :-( masalah dapat diatasi jika kita memuat pustaka gambar hanya sekali, di awal fungsi. dan hanya menginisialisasi konfigurasi untuk jempol kedua. kode yang berhasil adalah seperti di bawah untuk pengangkutan: -

{ function createThumb1 ($ imageName) // nama file dilewatkan     {

        // this thumbnail created
    $config['image_library'] = 'gd2';
    $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/uploads/'.$imageName;

    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = false;
    $config['width']     = 80;
    $config['height']   = 80;
    $config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/uploads/thumbs/'.$imageName;
    $this->load->library('image_lib', $config);
    if ( ! $this->image_lib->resize()){echo $this->image_lib->display_errors();}

    $this->image_lib->clear();

    // unable to create this this thumbnail
    $config['image_library'] = 'gd2';
    $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/uploads/'.$imageName;
    $config['create_thumb'] = FALSE;
    $config['maintain_ratio'] = false;
    $config['width']     = 696;
    $config['height']   = 241;
    $config['new_image'] =  $_SERVER['DOCUMENT_ROOT'].'/images/uploads/'.$imageName;
    //$this->load->library('image_lib', $config);  // this line cause problem
    $this->image_lib->initialize($config); // with this problem resolved
    if ( ! $this->image_lib->resize()){echo $this->image_lib->display_errors();}


    $this->image_lib->clear();






    $this->load->view('admin/upload_form',array('error' => ' ' ));





}

}


5
2017-08-02 04:10



Coba kosongkan konfigurasi Anda di bagian atas fungsi Anda menggunakan:

$this->image_lib->clear();

Anda juga dapat memeriksa kesalahan apa pun menggunakan:

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

Semoga ini membantu.


2
2017-08-01 05:04



hei terima kasih atas jawaban Anda

ya ini berfungsi untuk membuat di bagian akhir  $ this-> image_lib-> clear ();

dan untuk thambnail kedua     // $ this-> load-> library ('image_lib', $ config);

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

komentar keluar baris 1 dan ganti dengan yang kedua. permintaan Anda akan terpecahkan.


0
2017-08-05 21:17