Welcome Guest, Not a member yet? Register   Sign In
Images in CodeIgniter, how to?
#17

[eluser]JoostV[/eluser]
This is how you get a watermarked image from a folder and create that image if it does not yet exist. With a script like this you create thumbs the first time they are requested.

The function goes into a library, so you can reuse it as you see fit.

I did not test this script. You'll have to adjust as you go along)

LIBRARY watermark.php
Code:
function getThumbnail ($thumbnailPath, $filePath, $folder, $file)
{
    if (file_exists($thumbnailPath . $folder . $file) && is_file($thumbnailPath . $folder . $file)) {
        
        // Thumbnail is available. Return it.
        $src = $thumbnailPath . $folder . $file;
    }
    elseif (file_exists($filePath . $folder . $file) && is_file($filePath . $folder . $file)) {
        
        // Original file exists. Let's create a thumbnail
        $CI = & get_instance();
        
        // Create a new thumbnail folder if it does not exist
        if (! file_exists($thumbnailPath . $folder) || ! is_dir($thumbnailPath . $folder)) {
            mkdir($thumbnailPath . $folder);
            chmod($thumbnailPath . $folder, 0777);
        }
        
        // Create watermarked thumbnail and store in folder
        $config['source_image'] = $filePath . $folder . $file;
        $config['new_image'] = $thumbnailPath . $folder . $file;
        $config['source_image'] = '/path/to/image/mypic.jpg';
        $config['wm_text'] = 'Copyright 2006 - John Doe';
        $config['wm_type'] = 'text';
        $config['wm_font_path'] = './system/fonts/texb.ttf';
        $config['wm_font_size'] = '16';
        $config['wm_font_color'] = 'ffffff';
        $config['wm_vrt_alignment'] = 'bottom';
        $config['wm_hor_alignment'] = 'center';
        $config['wm_padding'] = '20';
        $CI->load->library('image_lib', $config);
        $CI->image_lib->watermark();
        
        // Return thumb we just created.
        $src = $thumbnailPath . $folder . $file;
    }
    else {
        
        // Oops, rhere is no orginal file. Return URL to a placeholder image.
        $src = 'images/no_image.png';
    }
    
    return $src;
}

CONTROLLER
Code:
$this->load->library('watermark');
$data['thumbnail']src = getThumbnail ($thumbnailPath, $filePath, $folder, $file);
$this->load->view('some_view', $data);


Messages In This Thread
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 04:20 AM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 04:27 AM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 12:51 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 04:42 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 06:50 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 06:53 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 07:15 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 07:27 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 07:35 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 07:43 PM
Images in CodeIgniter, how to? - by El Forum - 12-05-2009, 08:08 PM
Images in CodeIgniter, how to? - by El Forum - 12-06-2009, 01:50 AM
Images in CodeIgniter, how to? - by El Forum - 12-06-2009, 06:03 AM
Images in CodeIgniter, how to? - by El Forum - 12-06-2009, 06:28 AM
Images in CodeIgniter, how to? - by El Forum - 12-06-2009, 06:45 AM
Images in CodeIgniter, how to? - by El Forum - 12-06-2009, 07:33 AM
Images in CodeIgniter, how to? - by El Forum - 12-06-2009, 09:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB