I can't find any documentation on this. I'm uploading images and using
$config['create_thumb'] = TRUE;
to create a thumb and preserve the original image.
Is there a way to get the file name of the thumb image? _thumb is automatically added in the name for thumbnails but there's no function to extract the full name.
There really is a much easier way of doing this:
if ($this->upload->do_upload()) // If file was uploaded
{
$data = $this->upload->data(); // Returns information about your uploaded file.
$thumbnail = $data['raw_name'].'_thumb'.$data['file_ext']; // Here it is
}
CodeIgniter not providing any functions to extract the thumbnail name. It will add _thumb in your filename. If you want to write a custom function to get thumbnail name then use this.
function generate_thumb($filename, $path = '')
{
// if path is not given use default path //
if (!$path) {
$path = FCPATH . 'somedir' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
}
$config['image_library'] = 'gd2';
$config['source_image'] = $path . $filename;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
return FALSE;
}
// get file extension //
preg_match('/(?<extension>\.\w+)$/im', $filename, $matches);
$extension = $matches['extension'];
// thumbnail //
$thumbnail = preg_replace('/(\.\w+)$/im', '', $filename) . '_thumb' . $extension;
return $thumbnail;
}
Input :
echo generate_thumb('someimage.jpg');
echo generate_thumb('other_image.png', FCPATH . 'dirname' . DIRECTORY_SEPARATOR);
Output :
someimage_thumb.jpg
other_image_thumb.png
Hope this helps your. Thank you!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With