When I use gd and image processing functions on the source image, the image file size reduce hugely, even I set up the quality to 100.

For example, if I have 130x160 jpg file (file size, 176k), after I apply the gd or image functions on this file, such as resize etc. even the it is still a 130x160 jpg file, the file size reduced to 10 k.

Is there anyway that I can keep the image file size and so the quality?

When there is options in the image functions, I set it up as 100. But still I got file size reduced new image.

Thanks!

    do you really care about file size? or is it a quality issue?

      The quality issue. In my eyes the quality is ok. But the clients and graphic designers think the quality is sacrificed. That part is arguable so the proof is the file size reduced so much.

      I mean if I can increase the quality to the max. that is fine. But already set up the option parameter to be 100. What else I can do?

      Is this gd2 issue? gd2 auto compress the file and pick up the resolution the file should use? anything I can do to change the set up?

      Thanks!

        What kind of image processing do you do? Can you show us some sample code or a list of the GD functions you use?

          Chances are there may be some processing options that will help, such as using imagecopyresampled() instead of imagecopy(), but there will always be some fidelity loss when working with JPEGs, since they use a "lossy" compression algorithm.

            It was a codeigniter script. I have posted in codeigntier forum too. But this happens to regular imagejpeg etc. too

            //create largest dimension 480 px
                    $config['image_library'] = 'gd2';
                    $config['source_image'] = $data['upload_data']['full_path'];
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = 480;
                    $config['height'] = 480;
            $config['quality'] = 100;
            
            
                $this->image_lib->initialize($config);
            
            
                if (!$this->image_lib->resize()) {
            
                    $error = $this->image_lib->display_errors();
                    $this->session->set_flashdata('message',$error);
                    return false;
                } 
            

            this script resizes image to 480x480. I have a image file 480x480, and the file size is 30K. After running this script, I got a new image file still 480x480, but the file size reduced to 8K or so. I have set up the quality to be 100.

            this resize script is trying to resize file bigger than 480x480 to 480x480, but due to in the process, the file is compressed and the quality is not good. So I try to apply this script to a 480x480 source image just to see how much file size it will be reduced.

            My questions are

            1) this is gd2 issue, right? the image was auto compressed?
            2) anything I can do to keep the file size to be 50K, the graphic designer said the quality is not the same, when the file size turn from 50 K to 8K after the $this->image_lib->resize() was used.

            Because we are trying to allow user upload the photo through CMS based on codeigniter, and resize the photos on the fly. But the resized photos quality is not good to satisfy the graphic designers so the end users sometimes.

            Any help?

              I took a quick look at the CI code, and it has a lot of conditional processing depending on what GD functions are available, so it's difficult to know for sure what is happening in your case without injecting some debug code. If you have imagemagick installed on your PHP server, you could try changing "gd2" to "imagemagick" to see if that works any better for you.

                Write a Reply...