Welcome Guest, Not a member yet? Register   Sign In
Image helper
#1

[eluser]sumanchalki[/eluser]
I made an image resizing helper to help resize images with exact width or height supplied by user, using Codeigniter's Image library. Image will be cropped if needed. It can be configured to crop from different positions of the image.

Usage


Code:
$this->upload_image = BASEPATH.'../uploads/abc.jpg';
move_uploaded_file($_FILES['photo']['tmp_name'], $this->upload_image);

$config['source_image'] = $this->upload_image;
$config['thumb_marker'] = '-116';
$config['crop'] = true;
$config['crop_from'] = 'middle';
$config['width'] = 116;
$config['height'] = 76;
$config['small_image_resize'] = 'bigger';

resize_exact($config);

$config['thumb_marker'] = '-445';
$config['width'] = 445;
$config['height'] = 266;

resize_exact($config);


/* backup image */
$config['thumb_marker'] = '-big';
$config['crop'] = false;
$config['width'] = 800;
$config['height'] = 800;
$config['within_rectangle'] = true;
$config['small_image_resize'] = 'no_resize';

resize_exact($config);

In the above example, $config['crop'] = true, means image will be cropped, otherwise it has to be used as background of a div, no cropping will happen.

$config['crop_from'] = 'middle' means cropping will happen from middle; it behaves differently for landscape (width will be cropped) or portrait (height will be cropped) images.

The detail configuration is as follows:

@param array $config
$config['source_image'] -> source image
$config['thumb_marker'] -> thumb_marker
$config['width'] -> resize width
$config['height'] -> resize height
$config['within_rectangle'] -> true/false, default false,
if true, $config['crop']=false, config['small_image_resize']='inside'/'no_resize'

$config['crop'] -> true/false, default false, decides file will be croped as well
or only used in the background of a div
$config['crop_from'] -> 'start'/'middle'/'end', default start
$config['small_image_resize'] -> 'inside'/'bigger'/'no_resize', default bigger

I am using it for my projects and find it is very useful. I checked an open source image manipulation library:
http://wiki.github.com/masterexploder/PH...asic-usage

But it has some limitations, which I tried to cover.


Dependencies
It uses two functions namely getThumbName() and getSmallerDimension() which are included in the attached file.


Thanks
Suman




Theme © iAndrew 2016 - Forum software by © MyBB