EllisLab text mark
Advanced Search
     
Problem with resizing images
Posted: 12 November 2009 10:45 AM   [ Ignore ]
Joined: 2009-10-22
22 posts

Hi there,

Got a problem with resizing images. When initiated the image_lib library with the config option ‘create_thumb’ set to ‘true’ it wordks like charm. But i don’t need any thumbnails. Se when i do set the option ‘create_thumb’ to ‘false’ it doesn’t make a neat resized image. It creates i big black area within the height and width of the original picture and in the upper left corner is the resized version of the picture. All in one picture.
The used format is an jpg.

Here’s the code that initiates it from the controller:

$settings['maintain_ratio'TRUE;
    
$settings['image_library''gd2';
    
$settings['create_thumb'TRUE;
    
$settings['quality''70%';
    
$settings['width'100;
    
$settings['height'100;
    
$settings['source_image''uploads/pasfoto/'.$filename['file_name'];

        
$this->load->library('image_lib'$settings); 
        
$this->image_lib->resize();
    
            if ( ! 
$this->image_lib->resize())
            
{
                
echo $this->image_lib->display_errors();
            
}else{
                
            $this
->personeel_model->save_cursist_pasfoto($id$filename['file_name']);
            

Is there someone who can help me, with this? Otherwise i have to delete thumb pictures as well..

Grtz BrainCatcher

ps. Did i mentioned before?: U R Great!!

 
Posted: 12 November 2009 02:35 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-07
239 posts

not sure that this would cause a problem but you’re resizing the image twice ...

$this->image_lib->resize();
    
            if ( ! 
$this->image_lib->resize()) 
 Signature 

flemmingarnott.co.uk

 
Posted: 12 November 2009 04:10 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-10-22
22 posts

Yep you’re right. I didn’t look at it that way…Just tested it out and lookin good!!

Thnx tongue wink

 
Posted: 13 November 2009 07:14 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-07
239 posts

so that was all that was wrong?

 Signature 

flemmingarnott.co.uk

 
Posted: 13 November 2009 07:31 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2009-10-22
22 posts

Yes it was. Probably i didn’t realize when i wrote the code, that with the if-statement I did execute the resizing again. I ran a test with several different images. And it looks like it did solve the problem, which wasn’t really a problem related to CI’s image_lib library but to the coder. In fact, most of the time, that was me…..

Thnx again

 
Posted: 13 November 2009 07:33 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-07
239 posts

Excellent! Glad you got it sorted!

 Signature 

flemmingarnott.co.uk

 
Posted: 06 November 2012 02:18 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-10-29
124 posts

Mine doesnt work : (

public function resize($photo)
  
{
   $config[
'image_library''gd2';
   echo 
$config['source_image'$photo;
   echo 
$config['new_image''new.jpg';
   
//$config['create_thumb'] = TRUE;
   
$config['maintain_ratio'TRUE;
   
$config['width'75;
   
$config['height'50;
    
   
$this->load->library('image_lib'$config);
    
   
//$this->image_lib->resize();
   
if ( ! $this->image_lib->resize())
    
{
     $e 
$this->image_lib->display_errors();
     
print_($e);
    
}
   
else
    
{
     
//echo "resized";
    
}
  } 
 
Posted: 06 November 2012 02:25 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2012-10-29
124 posts

Mines resize() function is not resizing![I appreciate any help! code]<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Gallery extends CI_Controller
{

public function index()
  {
  $data[‘title’] = “Gallary Page”;
  $data[‘upload_data’]=”“;
  $this->load->vars($data);
  if($this->input->post(‘submit’))
  {
    $this->do_upload();
  }
  $this->load_photos();
  $this->view_things();
  }

function do_upload()
  {
  $config[‘upload_path’] = ‘uploads/’;
  $this->load->model(‘add_photo_model’);
  $data[‘new_photo’] = $this->add_photo_model->new_photo_name();
  $config[‘file_name’]  = $data[‘new_photo’];
  $config[‘overwrite’]  = TRUE;
  $config[‘allowed_types’] = ‘gif|jpg|png’;
  $config[‘max_size’] = ‘1000’;
  $config[‘max_width’]  = ‘1024’;
  $config[‘max_height’]  = ‘768’;
  $this->load->library(‘upload’, $config);
 
  if (!$this->upload->do_upload())
  {
    $data[‘upload_data’] = $this->upload->display_errors();
    $this->load->vars($data);
  }
  else
  {
    $photo[‘details’]= array(‘upload_data’ => $this->upload->data());
    $this->add_photo_model->add($data[‘new_photo’]);
   
    $data[‘upload_data’] = “The photo has been uploaded successfully”;
    $this->load->vars($data);
    $this->resize($data[‘new_photo’]);
  }
  }

public function resize($photo)
  {
  $config[‘image_library’] = ‘gd2’;
  echo $config[‘source_image’] = $photo;
  echo $config[‘new_image’] = ‘uploads/new.jpg’;
  $config[‘create_thumb’] = TRUE;
  $config[‘maintain_ratio’] = TRUE;
  $config[‘width’] = 75;
  $config[‘height’] = 50;
 
  $this->load->library(‘image_lib’, $config);
 
  //$this->image_lib->resize();
  if ( ! $this->image_lib->resize())
  {
    $e = $this->image_lib->display_errors();
    print_($e);
  }
  else
  {
    //echo “resized”;
  }
  }

public function load_photos()
  {
  $this->load->model(‘load_photos_model’);
  $photos = $this->load_photos_model->check();
  if($photos)
  {
    $photos_num_rows=0;
    foreach($photos as $row)
    {
    $photos_num_rows++;
    $data[‘photos’][]=$row->photo;
   
    }
    $data[‘photos_message’] = “There are “.$photos_num_rows.” photos uploaded so far”;
    $this->load->vars($data);
    return true;
  }
  else
  {
    $data[‘photos_message’] = “There are no photos uploaded yet!”;
    $this->load->vars($data);
  }
  }

  public function view_things()
  {
  $this->load->view(‘header_view’);
  $this->load->view(‘gallery_view’);
  $this->load->view(‘footer_view’);
  }
}

 
Posted: 06 November 2012 06:36 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-07
239 posts

hi,

I can see that you are echoing out some debugging info in: public function resize($photo), so what useful info is that displaying?

 Signature 

flemmingarnott.co.uk

 
Posted: 06 November 2012 08:45 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2012-10-29
124 posts
Flemming - 06 November 2012 06:36 AM

hi,

I can see that you are echoing out some debugging info in: public function resize($photo), so what useful info is that displaying?

Hey I sort it out! I had to add this:

$this->image_lib->initialize($config); 
 
Posted: 07 November 2012 07:29 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Joined: 2012-11-07
4 posts

A fast way to do this would be to use your crop tool. Set your height and width along with your desired resolution. Use the crop tool to select the area you would like and viola.