Welcome Guest, Not a member yet? Register   Sign In
unsightly resized image quality
#1

[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.');
#2

[eluser]diez[/eluser]
if your server supports GD2, then edit your $imageConfig ['image_library'] variable from 'GD' to 'GD2'

example:
$imageConfig ['image_library'] = 'GD2';

that will properly resize your images. i had the same problem until i changed my 'image_library' variable from 'GD' to 'GD2'

remember you got to calculate your own aspect ratio on your own. so once you figure out your proper height and width this should do a much better job resizing.

hope this helps!
#3

[eluser]sawatdee[/eluser]
I use a web host, so I am limited to what they have installed, GD only. I am using the following code to calculate my new width and height, and it works great when I don't use the CI image library. As far as I know, both algorithms use GD. I haven't examined the CI source code closely, but if others have had the same problem and GD works when I don't use the library, then I wonder if there could be a small bug in the library somewhere. Wish I had time to look into it.

Code:
$widthRatio = $widthMax / $imageData ['image_width'];
$heightRatio = $heightMax / $imageData ['image_height'];
$widthNew = $widthMax;
$heightNew = $heightMax;
if ($widthRatio <= $heightRatio)
{
    $widthNew = $imageData ['image_width'] * $widthRatio;
    $heightNew = $imageData ['image_height'] * $widthRatio;
}
else
{
    $widthNew = $imageData ['image_width'] * $heightRatio;
    $heightNew = $imageData ['image_height'] * $heightRatio;
}
#4

[eluser]elvix[/eluser]
i had the same problem -- but i switched to the imagemagick library and the issue went away.
#5

[eluser]graf[/eluser]
has anyone found a resolution for this issue?

I'm currently maintaining a site that utilizes GD Image & FFMPEG, i'm unable to upgrade to GD2 due to certain constraints. While building a new section/module for the site i ran into this issue:
Images after resizing loos over half of their color saturation...
Any suggestions?
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB