[eluser]Asinox[/eluser]
Hi guys, i need a litter help with this, i have a function that help me with thumbs, now im trying to make a square thumb (cropping), the function work fine, the problem is that the original image is resizing (is resizing normal not cropping).
working fine:
1.- the square thumb
problem with:
1.- the original image is resizing, and i need to keep the original image without resize (not cropping, no resize)
Thanks guys
CODE
Code:
function image_thumb($image_path, $height, $width)
{
// Get the CodeIgniter super object
$CI =& get_instance();
// Path to image thumbnail
$i = pathinfo($image_path);
$image_thumb = dirname($image_path) . '/' . $i['filename'] . '_' . $height . '_' . $width . '.jpg';
if( ! file_exists($image_thumb))
{
list($image_width, $image_height, $type, $attr) = getimagesize($image_path);
// LOAD LIBRARY
$CI->load->library('image_lib');
$scale = 1;
$final_width = $width;
$final_height = $height;
$x = $final_width/$image_width;
$y = $final_height/$image_height;
if($x < $y) {
$new_width = round($image_width *($final_height/$image_height));
$new_height = $final_height;
}
else {
$new_height = round($image_height *($final_width/$image_width));
$new_width = $final_width;
}
$to_crop_left = ($new_width - ($final_width *$scale))/2;
$to_crop_top = ($new_height - ($final_height *$scale))/2;
// CONFIGURE IMAGE LIBRARY
$config['image_library'] = 'GD2';
$config['source_image'] = $image_path;
$config['maintain_ratio'] = true;
$config['master_dim'] = 'width';
$config['width'] = $new_width;
$config['height'] = $new_height;
$config['quality'] = '100%';
$CI->image_lib->initialize($config);
$CI->image_lib->resize();
// now crop the image from the center
$config['image_library'] = 'GD2';
$config['source_image'] = $image_path;
$config['width'] = $final_width;
$config['new_image'] = $image_thumb;
$config['height'] = $final_height;
$config['x_axis'] = $to_crop_left;
$config['y_axis'] = $to_crop_top;
$config['maintain_ratio'] = false;
$CI->image_lib->initialize($config);
$CI->image_lib->crop();
$CI->image_lib->clear();
}
return img(array(
'src' => $image_thumb,
'alt' => ''
));
}