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

[eluser]Sinclair[/eluser]
Hi, once again, thanks for the reply.

I upload the images by FTP and insert data directly to the database because I will be the only user/administrator of the website.

I think this code generate UUID's only using a function: http://oxygene.sk/lukas/2009/10/uuid-gen...n-plpgsql/

The problem with this is that I need to change the name of the .jpg by hand.

What I was thinking to do is store the images outside public_html, but my problem is that I need to use image_lib to generate thumbnails on the fly, and I don't know if I can do this with images outside public_html. Besides that, I will use the watermarked images by image_lib in a ajax script...

And as I newbie at web developement I'am affraid of doing the process in the wrong way and not reach the objective...

Best solution for this poor web application?


Best Regards,
#12

[eluser]JoostV[/eluser]
Do not ever create thumbnails on the fly unless you store them in cache or a thumbs folder. It is just too stressful on your webserver.
#13

[eluser]Sinclair[/eluser]
[quote author="JoostV" date="1260107416"]Do not ever create thumbnails on the fly unless you store them in cache or a thumbs folder. It is just too stressful on your webserver.[/quote]

Hi, thanks for the reply.

And how I do that? You have any example?


Best Regards,
#14

[eluser]JoostV[/eluser]
On uploading an image simply watermark and resize the uploaded image and store it in a public directory. If you want to keep the original image too, watermark and resize a copy of the original image and store the original image in a different directory.
#15

[eluser]Sinclair[/eluser]
[quote author="JoostV" date="1260124133"]On uploading an image simply watermark and resize the uploaded image and store it in a public directory. If you want to keep the original image too, watermark and resize a copy of the original image and store the original image in a different directory.[/quote]

Thanks for the reply.

As I said earlier, I don't have any backoffice to upload images. The upload of images will be done using FTP. I was thinking in the solution of store the original images outside of public_html and use image_lib to watermark and thumbnail because I don't want to make those tasks by hand.

But I see that the general consensus is that this is not a good idea.
#16

[eluser]Sinclair[/eluser]
Well, I start looking to test if the solution of store images outside public_html is possible.

I have done a function "getImageFromOutside"

Code:
<?php  

function getImageFromOutside($filePath, $folder, $file)  {  

    if (file_exists($filePath . $folder . $file))  
    {        
      
        $contents = file_get_contents($filePath . $folder . $file);                  
        return $contents;    
    }
    
}

header('Content-type: image/jpeg');
echo getImageFromOutside('C:/xampp/images/', '1/', '1.jpg');

?>

Now, I need to know something. It is possible to use the value returned by the function and use that in "image_lib"?

And where should I put this function? In helpers?


Best Regards,
#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);




Theme © iAndrew 2016 - Forum software by © MyBB