Welcome Guest, Not a member yet? Register   Sign In
resizing 2 images after each other
#1

[eluser]spedax[/eluser]
Hi, if been trying to resize 2 images after each other, and it keeps acting weird.
My first image resizes correctly, to 200x200. The second picture resizes to 200 with and a random height, for no known reason.

Anyone know what might be wrong ?


Code:
// crop stuff
   $config['image_library'] = 'gd2';
  $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/design/'.$newname;
  $config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/design/thumb/'.$newname;
  $config['width'] = '200';
  $config['height'] = '200';
  $config['maintain_ratio'] = FALSE;
  $this->load->library('image_lib', $config);
  if ( ! $this->image_lib->resize())
  {
      die($this->image_lib->display_errors());
  }
  $this->image_lib->clear();
  // crop stuff
  $config2['image_library'] = 'gd2';
  $config2['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/design/'.$newname;
  $config2['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/design/canvas/'.$newname;
  $config2['width'] = '900';
  $config2['maintain_ratio'] = TRUE;
  $this->load->library('image_lib', $config2);
  if ( ! $this->image_lib->resize())
  {
      die($this->image_lib->display_errors());
  }

if tried multiple things but nothing seems to help
#2

[eluser]Silviu[/eluser]
Code:
//load the image maipulation class first...
$this->load->library('image_lib');

// crop stuff
$config = array();
$config['image_library'] = 'gd2';
$config['source_image'] = './images/design/'.$newname;
$config['new_image'] = './images/design/thumb/'.$newname;
$config['width'] = '200';
$config['height'] = '200';
$config['maintain_ratio'] = FALSE;
$this->image_lib->initialize($config);  //and then configure it for every operation
if ( ! $this->image_lib->resize())
{
  die($this->image_lib->display_errors());
}
$this->image_lib->clear(); //you might not need this

// crop stuff
$config = array();
$config['image_library'] = 'gd2';
$config['source_image'] = './images/design/'.$newname;
$config['new_image'] = './images/design/canvas/'.$newname;
$config['width'] = '900';
$config['maintain_ratio'] = TRUE;
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize())
{
  die($this->image_lib->display_errors());
}

CI's loader class can detect if a particular class is already loaded, and will abort the load in such a case.

You are loading the image manipulation class twice, and in your case, the second load operation fails, and your image manipulation class remains only partially configured (with values intended for cropping).

Try my example, see if it works as you want it.
#3

[eluser]spedax[/eluser]
yep this seems to fix the problem! many thanks




Theme © iAndrew 2016 - Forum software by © MyBB