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

[eluser]Sven Delle[/eluser]
I've got a (fairly) highres image I wanna upload (and use with a lightbox solution of some kind). And from that image I want to create a smaller version that is used in a gallery. And on top of that I want to create a small thumbnail for use as, erhm, thumbnail.

As far as I understand the Image Lib, you can target the source image for manipulation, or; you can create a copy, and (or) you can create a thumbnail at the same time.

Now, if I do this:

Code:
$config['image_library'] = 'gd2';
$config['source_image'] = 'new_images/' . $_FILES['userfile']['name'];
$config['new_image'] = 'new_images/s_' . $_FILES['userfile']['name']; // smaller version based on height set below
$config['create_thumb'] = TRUE; // this creates the _thumb suffix file
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'height';
$config['width'] = 200;
$config['height'] = 300;

I get a file with a prefix of s_ and a [name] suffix of _thumb as in s_filename_thumb.jpg!

Now, what I would expect as a user is a smaller image file with a prefix of s_ and ANOTHER THUMBNAIL file with a [name] suffix of _thumb - as in s_filename.jpg and filename_thumb.jpg - AND the ability to controls the thumbnail size just like I'd do the new_image version.

I find it hard to see how the thumbnail creation enters the picture and has ANY value if that is not the way it works. Am I missing some obvious properties, or?
#2

[eluser]CroNiX[/eluser]
You have to process the image twice to get 2 different results and reset the config values in between. Once for the resize, and then again for the thumbnail.
#3

[eluser]Sven Delle[/eluser]
Which means; there's no real benefit of having a thumbnail property that can be set to true, unless you want an exact copy of your processed image with a different name?

If that is the case, then it's bad 'user interface'. A property of 'copy' would be more appropriate.
#4

[eluser]CroNiX[/eluser]
No, it means when you create the thumbnail set it to true, if you are cropping or resizing or doing something else, set it to false. The image class can only perform ONE action at a time.
#5

[eluser]Sven Delle[/eluser]
So, as I stated: thumbnail = TRUE will create an exact copy of the processed file, only with a differenct name. I still don't see the point of a 'thumbnail' property in this context. As you still have to run the whole process again.

Now what WOULD make sense would be something like:

Code:
$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;

$config['create_thumb'] = TRUE;
$config['thumb_fix'] = 'prefix' OR 'suffix';
$config['thumb_fix_value'] = 't_';
$config['maintain_thumb_ratio'] = TRUE;
$config['thumb_dim'] = 'auto';
$config['thumb_width'] = 60;
$config['thumb_height'] = 60;

Which would give me the option of keeping the source image (for the lightbox version), create the gallery version AND a thumbnail version.

And then have the class run the process twice if thumbnail is set to true.
#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)?
#7

[eluser]Sven Delle[/eluser]
I think I'll start a fresh post on that one.




Theme © iAndrew 2016 - Forum software by © MyBB