Welcome Guest, Not a member yet? Register   Sign In
image resize library issues

I am using the image resize upon upload library. After the picture is resized, the quality is really bad. It's pixelated and sometimes the colors are off.
Here is my config array:

$config['upload_path'] = './productImages/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '200';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;

And then I have a resize function which is called from the upload function:

function resizeImage($image)
    $config['image_library'] = 'gd2';
    $config['source_image'] = "./productImages/".$image;
    $config['width'] = 100;
    $config['height'] = 100;
    $config['master_dim'] = 'width';
    $this->load->library('image_lib', $config);
    if(! $this->image_lib->resize()){
        echo $this->image_lib->display_errors();
Anything I can add/change/remove here to make the resized images not lose their quality?

Are you sure you use GD instead of GD2?
$config['image_library'] = 'gd2';

I'd recommend using ImageMagick where available. Also, can you confirm that you're scaling your image down and not up? If you're trying to make a smaller image bigger, then pixelation will occur.

Processing photos in a loop:
Took me longer than I wanted.

Docs are missing an entry for image_lib->initialize(), and that is the key.

The information is there, but you have to read the page slowly and carefully, like a gripping novel. I prefer griping. Which is not novel.

Just in case another has the same issue, here is what worked for me:

load lib
begin loop
set options
invoke method
end loop

// resize all pics in a folder (replace existing). We want a max size of 10K per thumb
    function rethumb()
        $picpath = $this->config->item('base_dir') . '/my/file/videos/image';
        foreach($aFiles AS $fn)
                $fn = $picpath . $fn;
                $filesize = filesize($fn);
                if ( ($filesize >0) AND ($filesize < 10240) )
                echo "<BR>$fn";
                $config['image_library']    = 'gd';
                $config['create_thumb']        = TRUE;
                $config['maintain_ratio']    = TRUE;
                $config['width']                    = 150;
                $config['height']                    = 150;
                $config['master_dim']            = 'width';
                $config['thumb_marker']        = '';
                $config['source_image']        = $fn;
                if ( ! $this->image_lib->resize() )
                     echo '<BR><B>' . $this->image_lib->display_errors() . '</B>';

PS: If you are using phpFox, take a look at your video image folder. Some of them thumbnails are .5MB !

I tried gd2 and put $config['quality'] = 100 in the config array but still I get image degradation. Below are links to the before and after of the upload and resize. The before was a 200 x 200 and the resize is a 100 x 100.



I can't understand what is happening. Does anyone else have this problem?

The resulting image is 126x125. I don't know if this is your problem. I thought you were going for 100x100, in any case, the aspect ration is slightly out by 1 pixel, which might explain the blurriness.

Sorry, the after picture was a screen shot so I didn't crop it exactly. I don't know why I didn't just right click save as...(so frustrated with this I stop thinking right). Indeed when I right click save as it is 100 x 100. So I think it is resizing correctly it just becomes blurry.

Has no one else used this the image library? If so did it work right? Could it be my crappy 1and1.com web server?

Well, to my knowledge, image manipulation can consume a lot of memory, so there might be a chance that the server configuration is stopping you from using too much memory, although I think that's unlikely.

Are you unable to use ImageMagick?

If I can find some time, I might run some experiments later on, but it won't be for at least another 8 hours.

I can use ImageMagick but I have to use SSH to install it. I never delt with SSH before so I am nervous I might screw something up big time. But if I have to, I might have to risk it.

What OS/distro are you running on your server?

Usually, you can just install from a repository, which is very simple. No need for compiling or any of that nonsense.

On my system, I just type this:

sudo aptitude install imagemagick

And then it's pretty much done.

Theme © iAndrew 2016 - Forum software by © MyBB