Welcome Guest, Not a member yet? Register   Sign In
Getting black background from cropping with the image library?
#1

[eluser]Althalos[/eluser]
Hello.

I am trying to create a square thumbnail by taking an image, scaling it down to the selected width (210px) and then cropping the image as to remove what's over on the side that is longer than the other.

Here's my code:
$config['source_image'] = dirname($path).'/'.$newName.'/'.$newName.'_645.png';
list($width, $height) = getimagesize($config['source_image']);

if($width < $height)
{
$config['master_dim'] = 'width';
$height_crop = $height-210;
$width_crop = 0;
}
else
{
$config['master_dim'] = 'height';
$width_crop = $width-210;
$height_crop = 0;
}

$config['width'] = 210;
$config['height'] = 210;
$config['new_image'] = dirname($path).'/'.$newName.'/'.$newName.'_210.png';

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

$this->image_lib->resize();

//Crop the smallest image to the size 210x210
$this->image_lib->clear();

$config['x_axis'] = $width_crop/2;
$config['y_axis'] = $height_crop/2;
$config['source_image'] = dirname($path).'/'.$newName.'/'.$newName.'_210.png';

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

$config['x_axis'] = $width-$width_crop/2;
$config['y_axis'] = $height-$height_crop/2;

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

I know the image I start out with is right. The image I end up with is a black square with the exact same dimensions as the image I started out with.

So,
1) Why don't the dimensions change
2) why is the image just a black rectangle, where did the photo go?

best regards


Messages In This Thread
Getting black background from cropping with the image library? - by El Forum - 07-18-2010, 09:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB