[eluser]sawatdee[/eluser]
I am resizing some images after they are uploaded using GD. When I use the CI image manipulation class, the quality of the resized image is horrible. Here is the code I use to do it.
Code:
$imageConfig ['image_library'] = 'GD';
$imageConfig ['source_image'] = $newFileName;
$imageConfig ['create_thumb'] = false;//true;
$imageConfig ['maintain_ratio'] = true;
$imageConfig ['width'] = $widthNew;
$imageConfig ['height'] = $heightNew;
$this->load->library ('image_lib', $imageConfig);
if (!$this->image_lib->resize ())
show_error ($this->image_lib->display_errors ());
But when I use the following code to do the same thing, the quality is great. As far as I know, these functions use GD as well. Have I missed a setting or something?
Note: $imageData comes from the uploaded image.
Code:
$resized = imagecreatetruecolor ($widthNew, $heightNew);
$original = imagecreatefromjpeg ($newFileName);
if (!imagecopyresized ($resized, $original, 0, 0, 0, 0, $widthNew, $heightNew, $imageData ['image_width'], $imageData ['image_height']))
show_error ('Failed to resize the photo.');
if (!imagejpeg ($resized, $newFileName))
show_error ('Failed to save the photo.');