Welcome Guest, Not a member yet? Register   Sign In
Square cropping from the center, is there an easier way? RESOLVED
#3

[eluser]JoostV[/eluser]
Ah I see!

The trick is to set width and height and adding $config['maintain_ratio'] = false;

I never tried this because, according to the User Guide, maintain_ratio is not used by $this->image_lib->crop();

Now it's just a matter of one or two extra lines of code. Thanks very much!

Code:
//Set config for img library
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin/';
$config['source_image'] = $filePath . $fileOldName;
$config['maintain_ratio'] = false;

//Set cropping for y or x axis, depending on image orientation
if ($fileData['image_width'] > $fileData['image_height']) {
    $config['width'] = $fileData['image_height'];
    $config['height'] = $fileData['image_height'];
    $config['x_axis'] = (($fileData['image_width'] / 2) - ($config['width'] / 2));
}
else {
    $config['height'] = $fileData['image_width'];
    $config['width'] = $fileData['image_width'];
    $config['y_axis'] = (($fileData['image_height'] / 2) - ($config['height'] / 2));
}

//Load image library and crop
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
if ($this->image_lib->crop()) {
    $error = $this->image_lib->display_errors();
}

//Clear image library settings so we can do some more image
//manipulations if we have to
$this->image_lib->clear();
unset($config);

$fileData is result array from uploading image using libary File Upload


Messages In This Thread
Square cropping from the center, is there an easier way? RESOLVED - by El Forum - 04-02-2008, 06:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB