Welcome Guest, Not a member yet? Register   Sign In
Image Librarie
#1

[eluser]Paulodemoc[/eluser]
Hello all...
I am having some trouble with image manipulation =/
I upload the picture, resize it and create a thumb...
But the problem is: if I upload two pictures at the same time, picture 1 is created and so is its thumb, but the second thumb actually is a copy of the first picture =/
But if I upload one picture at a time, it works perfectly...
The code I am using:

Code:
if($_FILES["lagence_cover"]['name'] != '')
{
    $_FILES["lagence_cover"]['name'] = $this->_removeAccents($_FILES["lagence_cover"]['name']);
    $file_image                     =        $this->_uploadFile("lagence_cover",'gif|jpg|png',$this->width,$this->height);
    if (!is_array($file_image)) {
        $mannequin['lagence_cover'] = $m->lagence_cover;
        $mannequin['lagence_thumb'] = $m->lagence_thumb;
        $this->session->set_userdata('errormsg',lang('error_upload_image'));
    }
    else {
          $mannequin['lagence_cover'] = $file_image['file'];
          if ($this->_createThumb($mannequin['lagence_cover'],$this->thumb_width,$this->thumb_height)) {
              $explode = explode(".",$mannequin['lagence_cover']);
              $mannequin['lagence_thumb'] = $explode[0].'_thumb.'.$explode[1];
              $new_file             =        getimagesize($this->folder.$mannequin['lagence_thumb']);
              if($new_file[0] > $this->thumb_width || $new_file[1] > $this->thumb_height)
              {
                unset($configCropThumb);
                    $this->image_lib->clear();
                    $configCropThumb['image_library']        = 'gd2';
                    $configCropThumb['source_image']         = $this->folder.$mannequin['lagence_thumb'];
                    $configCropThumb['create_thumb']         = FALSE;
                    $configCropThumb['maintain_ratio']       = FALSE;
                    $configCropThumb['height']               = $this->thumb_height;                
                    $configCropThumb['width']                = $this->thumb_width;
                    $configCropThumb['x_axis']               = ($new_file[0]/2) - ($this->thumb_width/2);
                    $configCropThumb['y_axis']               = ($new_file[1]/2) - ($this->thumb_height/2);
                        
                    $this->image_lib->initialize($configCropThumb);
                    $this->image_lib->crop();
              }
          }
    }
} else {
    $mannequin['lagence_cover'] = $m->lagence_cover;
    $mannequin['lagence_thumb'] = $m->lagence_thumb;
}
...
if($_FILES["collections_cover"]['name'] != '')
{
    $_FILES["collections_cover"]['name'] = $this->_removeAccents($_FILES["collections_cover"]['name']);
    $file_image                     =        $this->_uploadFile("collections_cover",'gif|jpg|png',$this->width,$this->height);
    if (!is_array($file_image)) {
        $mannequin['collections_cover'] = $m->collections_cover;
        $mannequin['collections_thumb'] = $m->collections_thumb;
        $this->session->set_userdata('errormsg',lang('error_upload_image'));
    }
    else {
          $mannequin['collections_cover'] = $file_image['file'];
          if ($this->_createThumb($mannequin['collections_cover'],$this->thumb_width,$this->thumb_height)) {
              $explode = explode(".",$mannequin['collections_cover']);
              $mannequin['collections_thumb'] = $explode[0].'_thumb.'.$explode[1];
              $new_file             =        getimagesize($this->folder.$mannequin['collections_thumb']);
              if($new_file[0] > $this->thumb_width || $new_file[1] > $this->thumb_height)
              {
                unset($configCropThumb);
                    $this->image_lib->clear();
                    $configCropThumb['image_library']        = 'gd2';
                    $configCropThumb['source_image']         = $this->folder.$mannequin['collections_thumb'];
                    $configCropThumb['create_thumb']         = FALSE;
                    $configCropThumb['maintain_ratio']       = FALSE;
                    $configCropThumb['height']               = $this->thumb_height;                
                    $configCropThumb['width']                = $this->thumb_width;
                    $configCropThumb['x_axis']               = ($new_file[0]/2) - ($this->thumb_width/2);
                    $configCropThumb['y_axis']               = ($new_file[1]/2) - ($this->thumb_height/2);
                        
                    $this->image_lib->initialize($configCropThumb);
                    $this->image_lib->crop();
              }
          }
    }
} else {
    $mannequin['collections_cover'] = $m->collections_cover;
    $mannequin['collections_thumb'] = $m->collections_thumb;
}

Can someone try and help me? I have no Idea what might be going on...

I'll post the Upload and Create Thumb functions, 'cause I couldn't paste it here...
#2

[eluser]Paulodemoc[/eluser]
Code:
the functions:

function _uploadFile($field,$allowed_types,$width,$height) {
$config['upload_path']         =          $this->folder;
$config['allowed_types']       =          $allowed_types;
$config['max_size']            =          '';
$config['max_width']           =          '';
$config['max_height']          =          '';
$config['remove_spaces']       =          TRUE;

$this->upload->initialize($config);

if (!$this->upload->do_upload($field)) :
  return $this->upload->display_errors();
else :
  $file_info        =       $this->upload->data();
  $data['file']     =       $file_info['file_name'];
  $data['fileURL']  =       base_url().$this->folder.$file_info['file_name'];
  
    $width_compare = $file_info['image_width'] - $width;
    $height_compare = $file_info['image_height'] - $height;
    $master_dim = '';
    if($width_compare < $height_compare) $master_dim = 'width';
    else if($height_compare < $width_compare) $master_dim = 'height';
    else if($height_compare == $width_compare) $master_dim = 'auto';
    $config['width']                = $width;                    
    $config['height']               = $height;                      
    $config['master_dim']           = $master_dim;


    if ($file_info['file_type'] == 'image/jpeg')
        $config['image_library']        = 'gd2';
    else
        $config['image_library']        = 'gd';
    $config['source_image']         = $this->folder.$file_info['file_name'];
    
    $explode                         =    explode(".", $file_info['file_name']);
    $config['create_thumb']         = FALSE;
    $config['maintain_ratio']       = TRUE;

    $this->image_lib->initialize($config);

    if (!$this->image_lib->resize()) {    
        echo $this->image_lib->display_errors();
    } else {
          $new_file             =        getimagesize($this->folder.$explode[0]."_mini.".$explode[1]);
          if($new_file[0] > $width || $new_file[1] > $height) {
                if ($file_info['file_type'] == 'image/jpeg')
                    $config['image_library']        = 'gd2';
                else
                    $config['image_library']        = 'gd';
                $config['source_image']         = $this->folder.$file_info['file_name'];
                $config['maintain_ratio']       = FALSE;
                
                $config['height']               = $height;                
                $config['width']                = $width;
                $config['x_axis']               = ($new_file[0]/2) - ($width/2);
                $config['y_axis']               = ($new_file[1]/2) - ($height/2);      
                $this->image_lib->initialize($config);
                
                if (!$this->image_lib->crop()){      
                    echo $this->image_lib->display_errors();
                }
          }
    }
  
  return $data;
endif;
}

function _createThumb($image,$width,$height) {
//      $explode              =        explode(".",$image);
//        $thumb                  =        $explode[0].'_thumb.'.$explode[1];
//        
//        if(preg_match('/[.](jpg)$/', $image)) {  
//            $im = imagecreatefromjpeg($this->folder . $image);  
//        } else if (preg_match('/[.](gif)$/', $image)) {  
//            $im = imagecreatefromgif($this->folder . $image);  
//        } else if (preg_match('/[.](png)$/', $image)) {  
//            $im = imagecreatefrompng($this->folder . $image);  
//        }  else $im = imagecreatefromjpeg($this->folder . $image);  
//        
//        $ox = imagesx($im);  
//        $oy = imagesy($im);  
//        
//        /*$nx = $width;  
//        $ny = floor($oy * ($height / $ox));  */
//        $ny = $height;
//        $nx = floor($ox * ($width / $oy));
//        
//        $nm = imagecreatetruecolor($nx, $ny);  
//        
//        imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);  
//        
//        if(imagejpeg($nm, $this->folder . $thumb))
//        {
//            return true;
//        } else {
//            return false;
//        }
$explode              =        explode(".",$image);
$thumb                  =        $explode[0].'_thumb.'.$explode[1];
$this->image_lib->clear();
$config['image_library']        =       'gd2';
$config['source_image']         =       $this->folder.$image;
$config['new_image']             =       $this->folder.$thumb;
$config['create_thumb']         =       FALSE;
$config['maintain_ratio']       =       TRUE;
$config['master_dim']           =       'width';
$config['width']                =       $width;
$config['height']               =       $height;

$this->image_lib->initialize($config);
if (!$this->image_lib->resize())
echo $this->image_lib->display_errors();
else
return "Success";
}

function _removeAccents($texto)
{
$a = array(
            '/[ÂÀÁÄÃ]/'=>'A',
            '/[âãàáä]/'=>'a',
            '/[ÊÈÉË]/'=>'E',
            '/[êèéë]/'=>'e',
            '/[ÎÍÌÏ]/'=>'I',
            '/[îíìï]/'=>'i',
            '/[ÔÕÒÓÖ]/'=>'O',
            '/[ôõòóö]/'=>'o',
            '/[ÛÙÚÜ]/'=>'U',
            '/[ûúùü]/'=>'u',
            '/ç/'=>'c',
            '/Ç/'=> 'C');

$texto = utf8_decode($texto);
return preg_replace(array_keys($a), array_values($a), $texto);
}




Theme © iAndrew 2016 - Forum software by © MyBB