From fc502c29681500f5d3cea0db2e8b6197ce879742 Mon Sep 17 00:00:00 2001 From: atomaka Date: Sun, 6 Nov 2011 00:57:35 -0400 Subject: [PATCH] Use CI built-in image manipulation library to create thumbnails. --- application/controllers/upload.php | 29 ++++++++++++++++++++++++----- thumbs/index.html | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 thumbs/index.html diff --git a/application/controllers/upload.php b/application/controllers/upload.php index eb0df90..df82ac0 100644 --- a/application/controllers/upload.php +++ b/application/controllers/upload.php @@ -10,10 +10,13 @@ class Upload extends CI_Controller { $temp_name = md5(rand()); - $config['file_name'] = $temp_name; - $config['max_size'] = 2048; - $config['upload_path'] = './uploads/'; - $config['allowed_types'] = 'gif|jpg|jpeg|png|bmp'; + $config = array( + 'file_name' => $temp_name, + 'max_size' => 2048, + 'upload_path' => './uploads/', + 'allowed_types' => 'gif|jpg|jpeg|png|bmp' + ); + $this->load->library('upload', $config); if (!$this->upload->do_upload('image')) { @@ -23,9 +26,25 @@ class Upload extends CI_Controller { $this->load->model('fileupload'); $file_name = $this->fileupload->add_upload($upload['file_ext'], $upload['client_name']); - rename($upload['full_path'], $upload['file_path'] . $file_name . $upload['file_ext']); + $config = array( + 'image_library' => 'gd2', + 'source_image' => $upload['file_path'] . $file_name . $upload['file_ext'], + 'create_thumb' => true, + 'maintain_ratio' => true, + 'width' => 175, + 'height' => 50, + 'new_image' => './thumbs/' . $file_name . $upload['file_ext'], + 'thumb_marker' => '', + ); + + $this->load->library('image_lib',$config); + + if($this->image_lib->resize() != true) echo 'dead to me.'; + + echo $this->image_lib->display_errors(); + $message = array('type'=>'success','status'=>'Uploaded successfully', 'file'=>base_url('/view/specific/' . $file_name)); } diff --git a/thumbs/index.html b/thumbs/index.html new file mode 100644 index 0000000..7673893 --- /dev/null +++ b/thumbs/index.html @@ -0,0 +1 @@ +Nothing here \ No newline at end of file