Welcome Guest, Not a member yet? Register   Sign In
can anyone successfully crop image with image lib ?
#1

[eluser]runrun[/eluser]
I try many way and i still can't get it right. If you've done it before, maybe you can share some experience ?

I got the image uploaded. I got the image resized. The crop is the problem here.

Code:
<?php

class Img extends Controller {
    function index()
    {
        $this->load->view('img_view.php');
    }
    function process()
    {
        $config['upload_path'] = FCPATH.'img/';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['file_name'] = time().'_tictac';
        $config['max_size']    = '2048';
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $this->load->library('image_lib');    
        
    
        $info = $this->upload->data();
        $this->_createThumbnail($info['file_name']);
        $this->_cropThumbnail($info['raw_name'].'_thumb'.$info['file_ext']);
            
    function _createThumbnail($fileName)
    {
        $config['image_library'] = 'gd2';
        $config['source_image'] = FCPATH.'img/' . $fileName;    
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['quality'] = '100%';
        $config['width'] = 200;
        $config['height'] = 200;
        
        $this->image_lib->initialize($config);
        $this->image_lib->resize();

    }
    function _cropThumbnail($thumbName)
    {    
        $config['image_library'] = 'imagemagick';
        $config['quality'] = '100%';
        $config['x_axis'] = 88 ;
        $config['y_axis'] = 66 ;
        $this->image_lib->initialize($config);
        $this->image_lib->crop();
    }
}
#2

[eluser]xarazar[/eluser]
It's probably too late and you already know the answer, but just in case:
When you use ImageMagick you must specify $config['library_path'].
Good luck!
#3

[eluser]eoinmcg[/eluser]
Here's some code from my gallery app, QuickSnaps, that handles cropping:

Code:
function _crop_image($p, $x_off, $y_off)
    {

        $config['image_library'] = 'imagemagick';
        $config['library_path'] = '/usr/bin/convert';
        $config['source_image'] = './'.$p->photo.$p->photo_type;
        $config['maintain_ratio'] = FALSE;
        $config['x_axis'] = ceil ( $this->input->post('x') * $x_off );
        $config['y_axis'] = ceil ( $this->input->post('y') * $y_off );
        $config['width'] = $this->input->post('w') * $x_off;
        $config['height'] = $this->input->post('h') * $y_off;

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


        if ( ! $this->image_lib->crop())
        {
            echo $this->image_lib->display_errors();
        }

        $this->image_lib->clear();

    }
#4

[eluser]stommert[/eluser]
you have to clear your image lib. stated in the last example $this->image_lib->clear();




Theme © iAndrew 2016 - Forum software by © MyBB