Welcome Guest, Not a member yet? Register   Sign In
Problem with image lib
#1

[eluser]tweester[/eluser]
Hi!

I have a problem with image library:
It displays an error : Your server does not support the GD function required to process this type of image.
This error was cosed by using
$this->image_lib->clear();

In fact I wanted to upload and make thumbnails of multiple fotos. This fotos are uploading but not making a thumbnail (...

I've already checked gd_info and $config by making var_dump.

It seems like script didn't change tmp_name... Here is a code...:

Code:
$lastid=mysql_insert_id();
            for($i=1;$i<=5;$i++)
            {
                if(is_uploaded_file($_FILES['myfile'.$i]['tmp_name']))
                {
                    $name=$_FILES['myfile'.$i];
                    $this->upload_img($lastid.$i,$name);
                }
            }

Code:
function upload_img($last_insert_id,$name)
    {
        $errors=array();
        $upf=NULL;
        $tmp=NULL;
        $config['image_library']= 'gd2';            
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 110;
        $config['height'] = 140;

        if(is_uploaded_file($name['tmp_name']))
         {
            $upf=$name['tmp_name'];
        $path='';
        $path=$_SERVER['DOCUMENT_ROOT']."/img/upload/".$last_insert_id.".jpg";
        $config['source_image'] = $upf;
        $config['new_image'] = $path;
        $this->load->library('image_lib',$config);
        $res=$this->image_lib->resize();
        $this->image_lib->clear();
            if(!res )echo $this->image_lib->display_errors();
        copy($upf,$path);
            unlink($upf);
         }

P.s. sorry for my bad English
#2

[eluser]tweester[/eluser]
I've forgotten : This script creates 1 thumbnail (of the first image).
#3

[eluser]gunter[/eluser]
[quote author="tweester" date="1205787876"]I've forgotten : This script creates 1 thumbnail (of the first image).[/quote]

thats an important info!
$this->load->library('image_lib',$config); this loads the library and passes the $config array... but if the library is already loaded the array will not passed and initialized...

so load the library only once with $this->load->library('image_lib'); and whereever you want to initialize the array then use the other function (look at the guide...)
okay?
#4

[eluser]tweester[/eluser]
Huh.. Thanks

Code:
$this->image_lib->initialize($config);
helped me...
#5

[eluser]barbazul[/eluser]
Guys, similar problem here:

I have a model method that recieves a path to an image file and makes 5 copies of it with different dimensions (original, 50x50 thumbnail, 480x360, 200x150 and 100x75)

Basically I copy() the first one, resize as thumbnail then crop for the second one, then resize and crop for the third and finally resize the third one and set a new filename to create number 4 and 5.

The controller method is very simple:

Code:
foreach($paths as $path) {
    $this->photo->create($path);
}

Each of the model methods that actually manipulate the files look similar to this (no point in copying it excactly):

Code:
private function _copyMain($path)
{
    $image_lib_config['image_library'] = 'gd2';
    $image_lib_config['source_image'] = $path;
    $image_lib_config['create_thumb'] = FALSE;
    $image_lib_config['maintain_ratio'] = TRUE;
    $image_lib_config['new_image'] = 'somename.jpg'; // I generate unique filenames foreach with another method
    $image_lib_config['quality'] = 85;
    $image_lib_config['width'] = 200;
    $image_lib_config['height'] = 150;
    $this->image_lib->initialize($image_lib_config);
    $this->image_lib->resize();
    
    $this->image_lib->clear();    
}

Options change from method to method.
For instance, different with/height
I only set the 'create_thumb' option to TRUE for the 50x50 thumbnail

So, the tricky part is that the FIRST one works perfectly, but each image thereafter fails to create a thumbnail but instead resizes the original to 50x50 which obviously breaks each new copy after that (they enlarge the 50x50 thumb instead of shrinking the original picture)

Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB