Welcome Guest, Not a member yet? Register   Sign In
Perfect thumbs (Image Manipulation Class)
#1

[eluser]Drula[/eluser]
Hi,

I using code listed below from ( http://ellislab.com/forums/viewthread/85727/ ) to create thumbs:

Code:
function process_uploaded_image($filename){
    
    $large_path = $this->config->item('portfolio_path').$filename;
    $thumb_path = $this->config->item('thumbs_path').$filename;
    
    //get image size
    $img_size = getimagesize($large_path);
    $orig_width = $img_size[0];
    $orig_height = $img_size[1];
    
    if($orig_width > $orig_height) {
    //horizontal picture
        $res_width = 450;
        $res_height = 10;
        $set_master_dim = 'width';
    } else {
    //vertical picture
        $res_width = 10;
        $res_height = 400;
        $set_master_dim = 'height';
    }
    
    //resizing the uploaded image
    $resize_config['image_library'] = 'gd2';
    $resize_config['source_image'] = $large_path;
    $resize_config['maintain_ratio'] = TRUE;
    $resize_config['width'] = $res_width;
    $resize_config['height'] = $res_height;
    $resize_config['master_dim'] = $set_master_dim;
    
    $this->load->library('image_lib', $resize_config);
    
    if (!$this->image_lib->resize()) {
        echo "fout bij eerste resize";
        echo $this->image_lib->display_errors();
        return false;
    }
    
    //making a thumbnail
    $this->image_lib->clear();
    
    //get image size
    $img_size = getimagesize($large_path);
    $orig_width = $img_size[0];
    $orig_height = $img_size[1];
    
    //calculate offset
    if($orig_width > $orig_height) {
    //horizontal picture
        $diff = $orig_width - $orig_height;
        $cropsize = $orig_height - 1;
        $x_axis = round($diff / 2);
        $y_axis = 0;
    } else {
    //vertical picture
        $cropsize = $orig_width - 1;
        $diff = $orig_height - $orig_width;
        $x_axis = 0;
        $y_axis = round($diff / 2);
    }
    
    //actual cropping
    $crop_config['image_library'] = 'gd2';
    $crop_config['source_image'] = $large_path;
    $crop_config['maintain_ratio'] = FALSE;
    $crop_config['new_image'] = $thumb_path;
    $crop_config['x_axis'] = $x_axis;
    $crop_config['y_axis'] = $y_axis;
    $crop_config['width'] = $cropsize;
    $crop_config['height'] = $cropsize;
        
    $this->image_lib->initialize($crop_config);

    if (!$this->image_lib->crop()) {
        echo "fout bij crop";
        echo $this->image_lib->display_errors();
        return false;
    }
    
    
    //resize the cropped image to a thumbnail
    $this->image_lib->clear();
    
    $thumb_config['image_library'] = 'gd2';
    $thumb_config['source_image'] = $thumb_path;
    $thumb_config['maintain_ratio'] = TRUE;
    $thumb_config['width'] = 100;
    $thumb_config['height'] = 100;
    
    $this->image_lib->initialize($thumb_config);
    
    if (!$this->image_lib->resize()) {
        echo "fout bij resizen crop";
        echo $this->image_lib->display_errors();
        return false;
    }
    
    //watermark the resized image
    $this->image_lib->clear();
    
    $wm_config['source_image'] = $large_path;
    $wm_config['wm_type'] = 'overlay';
    $wm_config['wm_vrt_alignment'] = 'middle';
    $wm_config['wm_hor_alignment'] = 'center';
    $wm_config['wm_overlay_path'] = './images/shutter_watermark.png';
    
    $this->image_lib->initialize($wm_config);
    
    if (!$this->image_lib->watermark()) {
        echo "fout bij watermarken";
        echo $this->image_lib->display_errors();
        return false;
    }
    
    return true;    
    
}

It's workign and thumbs looks like ( from image: http://i.imgur.com/Vb11h.jpg ):

http://i.imgur.com/21fEf.jpg

but I want thumbs like:

http://i.imgur.com/fcLEa.jpg


Could You help me?
#2

[eluser]Sanjay Sarvaiya[/eluser]
Have you tried this?
Code:
$thumb_config['maintain_ratio'] = FALSE;
#3

[eluser]Drula[/eluser]
Yes, but unfortunately this makes no difference, no results.
#4

[eluser]Drula[/eluser]
ok, I found http://www.matmoo.com/digital-dribble/co...image_moo/ its great and it's solve my problems Smile




Theme © iAndrew 2016 - Forum software by © MyBB