Resize image with Codeigniter with low quality

5.9k Views Asked by At

I am using CodeIgniter to resize image, but the small image I have resized is low quality. Here is my code:

$config = array(
    'image_library' => 'gd2',
    'quality' => '100',
    'source_image' => $temp_full_path,
    'new_image' => $full_temp_path."img_mobile/",
    'maintain_ratio' => true,
    'create_thumb' => false,
    'width' => 50,
    'height' => 50
);              
$this->image_lib->initialize($config);              
$this->image_lib->resize();

How can make resize image with high quality like it's original image?

Here is original image, image resize generate from php code and image resize generate from codeigniter: Image

4

There are 4 best solutions below

0
On

Looking at the source code, GD2 doesn't use the "quality" parameter.

But some of the other libraries do use it.

Give ImageMagick a try.

2
On

It's a small mistake or a pitfall.

Do:

'quality' => '100%',

instead of

'quality' => '100',

Should work, according to docs.

EDIT:

There seems to be another typo!

'maintain_ration'

should be

'maintain_ratio'

Also, how can new_image end with a /? you are doing something wrong there.

0
On

You should write 'quality' => '100%' instead of only '100'

0
On

Default:

$config['image_library'] = 'gd2';

Alternative:

$config['image_library'] = 'gd';
$config['quality']       = 100;

Best Quality:

$config['image_library'] = 'imagemagick'; 
$config['library_path']  = "/usr/bin"; 
$config['quality']       = 100;

Codeigniter Image Quality

Ref: https://forum.codeigniter.com/thread-17374.html