CodeIgniter Forums
image resize library issues - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: image resize library issues (/thread-16950.html)

Pages: 1 2


image resize library issues - El Forum - 03-21-2009

[eluser]bennyhill[/eluser]
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:

Code:
$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:

Code:
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?


image resize library issues - El Forum - 03-21-2009

[eluser]pistolPete[/eluser]
Are you sure you use GD instead of GD2?
Try
Code:
$config['image_library'] = 'gd2';



image resize library issues - El Forum - 03-21-2009

[eluser]TheFuzzy0ne[/eluser]
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.


image resize library issues - El Forum - 03-23-2009

[eluser]steward[/eluser]
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
clear
set options
initialize
invoke method
end loop

Code:
// 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';
        $this->load->library('image_lib');
        $aFiles=$this->get_files($picpath);
        foreach($aFiles AS $fn)
        {
                $fn = $picpath . $fn;
                $filesize = filesize($fn);
                if ( ($filesize >0) AND ($filesize < 10240) )
                {
                  continue;
                }
                echo "<BR>$fn";
                $this->image_lib->clear();
                $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;
                $this->image_lib->initialize($config);
                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 !


image resize library issues - El Forum - 03-29-2009

[eluser]bennyhill[/eluser]
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.

Before


After


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


image resize library issues - El Forum - 03-29-2009

[eluser]TheFuzzy0ne[/eluser]
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.


image resize library issues - El Forum - 03-30-2009

[eluser]bennyhill[/eluser]
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?


image resize library issues - El Forum - 03-30-2009

[eluser]TheFuzzy0ne[/eluser]
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.


image resize library issues - El Forum - 03-30-2009

[eluser]bennyhill[/eluser]
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.


image resize library issues - El Forum - 03-30-2009

[eluser]TheFuzzy0ne[/eluser]
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.