CodeIgniter Forums
can anyone successfully crop image with image lib ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: can anyone successfully crop image with image lib ? (/showthread.php?tid=26012)



can anyone successfully crop image with image lib ? - El Forum - 01-03-2010

[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();
    }
}



can anyone successfully crop image with image lib ? - El Forum - 02-09-2010

[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!


can anyone successfully crop image with image lib ? - El Forum - 02-09-2010

[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();

    }



can anyone successfully crop image with image lib ? - El Forum - 02-10-2010

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