Welcome Guest, Not a member yet? Register   Sign In
Basic use of Image Lib ... ?
#6

[eluser]Sven Delle[/eluser]
This is what I came up with to get what I wanted:

Code:
public function create_small_image()
{  
$config['image_library'] = 'gd2';
$config['source_image'] = 'new_images/' . $_FILES['userfile']['name'];
$config['new_image'] = 'new_images/s_' . $_FILES['userfile']['name'];
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'height';
$config['width'] = 200;
$config['height'] = 300;
  
$this->load->library('image_lib', $config);

if($this->image_lib->resize())
{
  $config['image_library'] = 'gd2';
  $config['source_image'] = 'new_images/' . $_FILES['userfile']['name'];
  $config['new_image'] = 'new_images/t_' . $_FILES['userfile']['name'];
  $config['maintain_ratio'] = TRUE;
  $config['master_dim'] = 'auto';
  $config['width'] = 32;
  $config['height'] = 32;
  
  $this->image_lib->initialize($config);
  
  if($this->image_lib->resize())
  {
   return true;
  }
}
else
{
  return false;
}
}

But I still got ONE problem to solve:

How to I get the image aspect ratio to maintain a minimum of either height or width?

Let me explain: I have a square thumbnail slot that is 32 by 32 pixels. How do I make sure that no matter whether the image is wider that taller or taller than wider it will ALWAYS fill the entire thumbnail slot?

That is: if the image is 431 wide and 600 tall, and I set the width and height to 32, and the maintain_ratio to auto - I only get an image with a height of 32 pixels (as this is the 'auto' side that is the longest) but a width of only 23 pixels.

How do I configure this to always have a height or a width that is 32 pixels on the shortest length (width or height)?


Messages In This Thread
Basic use of Image Lib ... ? - by El Forum - 05-09-2012, 01:25 PM
Basic use of Image Lib ... ? - by El Forum - 05-09-2012, 02:49 PM
Basic use of Image Lib ... ? - by El Forum - 05-14-2012, 02:24 AM
Basic use of Image Lib ... ? - by El Forum - 05-14-2012, 08:40 AM
Basic use of Image Lib ... ? - by El Forum - 05-15-2012, 12:31 AM
Basic use of Image Lib ... ? - by El Forum - 05-15-2012, 01:06 AM
Basic use of Image Lib ... ? - by El Forum - 05-15-2012, 01:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB