Welcome Guest, Not a member yet? Register   Sign In
help with thumbs square and CI (just a litter help)
#1

[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' => ''
    ));
}
#2

[eluser]slowgary[/eluser]
There's a config item called 'new_image' that allows you to specify a new path/filename so that you don't overwrite the original. It's documented in the userguide.
#3

[eluser]Asinox[/eluser]
Hi slowgary, yes i know about new_image, the problem is that i want to try without another path.
#4

[eluser]slowgary[/eluser]
So don't specify the path. If you only specify a new name, it should use the original path. If not, just do a bit of string manipulation on your original path to remove the filename, and pass that in with your new file name as $config['new_image'].




Theme © iAndrew 2016 - Forum software by © MyBB