Welcome Guest, Not a member yet? Register   Sign In
Resize image without distortion
#1

[eluser]Ingonyama[/eluser]
Heres a small library I made a few weeks ago to resize images into a rectangle from the center.

Example: http://img201.imageshack.us/img201/1236/examplel.jpg

Initialize the class by passing in the following params:
Code:
$config['save_directory'] = './res/uploads/'; // where to save the resized image
$config['new_width'] = 100; // the width you want to resize to
$config['new_height'] = 100; // the height you want to resize to
$config['thumb_marker'] = '_thumb'; // by default its _thumb but you can add your own

$this->load->library('resize', $config);

Then input the file path of the file you want to resize and the name you want to save it as

Code:
$file_path = '/path/to/image.jpg';
$save_name = 'foobar'; // no need to include the file extension
if ($this->resize->process($file_path, $save_name))
{
    echo 'It worked';
}
else
{
    echo 'Something went wrong';
    echo $this->resize->error_log();
}

Comments, improvements, bug reports etc all welcome.




Theme © iAndrew 2016 - Forum software by © MyBB