2016-09-19 4 views
1

Ich möchte das Bild auf 160 x 160 skalieren und ein Thumbnail davon machen und dieses Thumbnail dann im Ordner speichern. Ich möchte das reale Bild nicht speichern, sondern nur das Miniaturbild. Unten ist mein Code:make image thumbnail vor dem Hochladen - php codeigniter

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

    $this->load->library('image_lib');  

    $blog_image = $_FILES['blog_image']['name']; 

    $config = array ('upload_path' => './blogs/', 
        'allowed_types' => "jpeg|jpg|png", 
        'overwrite' => TRUE, 
        'image_library' => 'gd2', 
        'source_image' => $blog_image, 
        'create_thumb' => TRUE, 
        'maintain_ratio' => TRUE, 
        'width' => 160, 
        'height' => 160 
        ); 

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

$this->upload->do_upload('blog_image'); 

$this->image_lib->resize(); 

Dieser Code funktioniert nicht. Das Bild wird hochgeladen, ohne es zu vergrößern. Bitte Hilfe.

+0

Ist auf Ihrem Server GD/GD2, NetPBM oder ImageMagick installiert? – alloyking

+0

Ich weiß es nicht. Wie kann ich das überprüfen? Ich arbeite gerade an meinem localhost AppServ –

+0

Sind Sie auf Windows, Mac oder Linux? – alloyking

Antwort

0
$config['image_library'] = 'gd2'; 
$config['source_image'] = $_FILES['image']['tmp_name']; 
$config['new_image'] = $target_path 
$config['maintain_ratio'] = TRUE; 
$config['width'] = 160; 
$config['height'] = 160; 

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

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

Check Link für weitere Informationen ... https://stackoverflow.com/a/13154916/6588826

0

Versuchen unter Beispielcode.

$config = array(
     'upload_path' => './blogs/', 
     'allowed_types' => 'jpg|png|gif', 
     'max_filename' => '255', 
     'encrypt_name' => TRUE, 

    ); 


    $this->load->library('upload', $config); 
    //check file successfully uploaded. 'blog_image' is the name of the input 
    if ($this->upload->do_upload('blog_image')) { 
     //Now go to resize 
     $image_data = $this->upload->data(); 
     $config_resize = array(
       'image_library' => 'gd2', 
       'source_image' => $image_data['full_path'], //get original image 
       'maintain_ratio' => TRUE, 
       'width' => 160, 
       'height' => 160 
      ); 

     $this->load->library('image_lib', $config_resize); 
     if (!$this->image_lib->resize()) { 

      print_r($this->image_lib->display_errors()); 
     } 
    }else{ 
     print_r($this->upload->display_errors()); 
    } 
Verwandte Themen