Welcome Guest, Not a member yet? Register   Sign In
Generate Thumbnails (Image Lib Resize)
#1

[eluser]gRoberts[/eluser]
Hey all,

Can anyone point out a reason why this wont work? It doesn't report any issues, but also doesn't create an image.

Code:
function generateThumbnail($base, $source, $output, $width, $height, $watermark = true) {
        $dir = dirname($output);
        if(!is_dir($dir))
            recursive_mkdir($dir);
                
        $config['image_library'] = 'GD';
        $config['source_image'] = $source;
        $config['create_thumb'] = true;
        $config['new_image'] = $output;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = $width;
        $config['height'] = $height;
        
        $base->load->library('image_lib', $config);
        if(!$base->image_lib->resize())
            echo 'Unable to create thumbnail';
        
        if($watermark)
            applyWatermarkToImage($base, $output);    
        
    }

Any advice would be appreciated!

Cheers
#2

[eluser]Matthew Lanham[/eluser]
Is the directory where the thumbails are to be stored chmod 777?
#3

[eluser]gRoberts[/eluser]
yep. Its very strange as the folder layout

images/item/100x100
images/item/250x250

My code is meant to create two thumbnails and put them into the above folders and it then copies the original image into

images/item

And it only copies the image to the images/item folder.

Cheers
#4

[eluser]Matthew Lanham[/eluser]
What is the value of $output?
#5

[eluser]tonanbarbarian[/eluser]
Where does your function exist?
Is it in a helper, controller or library?

Not sure if any of these will help but they might...

1. No matter where this is being running from I am assuming the $base is an instance of the CI controller.
The first issue is that you are not passing that into the function by reference so it might be having problems due to that.
The main issue is that it might not load the image library properly, although I would expect that to produce an error.

2. Other issue is that I have found an occasion where there was problems with image generation because even though the width and height values were numbers they were of the string type rather than an integer

If you are running the code from a CI controller then just reference the $base as $this. If you are running from a library or helpder then I recommend making an instance of the CI as in the example provided below

Code:
function generateThumbnail($source, $output, $width, $height, $watermark = true) {
        $CI =& get_instance();

        $dir = dirname($output);
        if(!is_dir($dir))
            recursive_mkdir($dir);
                
        $config['image_library'] = 'GD';
        $config['source_image'] = $source;
        $config['create_thumb'] = true;
        $config['new_image'] = $output;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = (int)$width;
        $config['height'] = (int)$height;
        
        $CI->load->library('image_lib', $config);
        if(!$CI->image_lib->resize())
            echo 'Unable to create thumbnail';
        
        if($watermark)
            applyWatermarkToImage($base, $output);    
        
    }
#6

[eluser]gRoberts[/eluser]
hey thanks, its a file thats based in the application/libraries file but is included in the controller constructor.

$base is in fact $this when it is called. The reason for that was even thought i included the php file containing the function, $this is not the CI instance, so I used $base as a bridge.

I'll give your get_instance a bash, and let you know asap.

Thanks
#7

[eluser]gRoberts[/eluser]
Well I think its a permissions issue as I put touch($filename) before the calls and it throws errors regarding permissions, now the strange thing is why the permissions are not correct as I can create a thumbnail in the folder I'm uploading to, and they all have been set to 777.

I'll look into it.

Thanks again
#8

[eluser]gRoberts[/eluser]
Well it was down to a permissions issue. For some strange reason my FTP program wasn't setting it to 777 properly.

now its fixed, its not creating thumbnails correctly.

Instead of creating the thumbnail, it just appears to create a copy of the original in the folder I gave (and if required, it also adds the watermark)

Any idea's?




Theme © iAndrew 2016 - Forum software by © MyBB