Hi,

I have created a page for an adminstrator to upload a picture. The picture is resized on the server. One to a thumbnail and one to a bigger size.

However the quality to which these pictures are stored are very bad.

How do i retain the original quality.

imagejpeg($dst_im, $destinationFileName,100);

I understand the above line has something to do with it.

PLEASE HELP. this is the last thing i need to do.

Thanks in advance

Kam

    Originally posted by vishnura
    I have created a page for an adminstrator to upload a picture. The picture is resized on the server. One to a thumbnail and one to a bigger size.

    However the quality to which these pictures are stored are very bad.

    Post some code for us to see.

      How do you mean "the image quality is very bad"? Is it something like what is described in this FAQ?

        here is the code that i have used. It does its job apart from the image quality thing.

        	
        $url= $_FILES['url'];
        $srcFileName = $_FILES['url']['tmp_name'];
        $newFileName= "/v5/media/arts/thumbnails/".$_FILES['url']['name'];
        resizeAndCopy($srcFileName, $newFileName, 164, 109);	
        $newFileNameFull = "/v5/media/arts/full/".$_FILES['url']['name'];
        resizeAndCopy($srcFileName, $newFileNameFull, 654, 436);
        

        The resizeAndCopy(...) method is outlined below.

        
        function resizeAndCopy($sourceFileName, $destinationFileName, $maxWidth, $maxHeight)
        {
        	$src_im = imagecreatefromjpeg($sourceFileName);
        	$srcHeight = imagesy($src_im);
        	$srcWidth = imagesx($src_im);
        	$height = imagesy($src_im);
        	$width = imagesx($src_im);
        	if($height>$maxHeight)
        	{
        		$x=(int)($maxHeight/($height/100));
        		$width = (int)($x*($width/100));
        		$height = $maxHeight;
        	}
        	if($width>$maxWidth)
        	{
        		$x = (int)($maxWidth/($width/100));
        		$height = (int)($x*($height/100));
        		$width = $maxWidth;
        	}
        
        	$dst_im = imagecreate($width, $height);
        	echo "$srcWidth, $srcHeight, $width, $height <br>";
        	echo "$sourceFileName, $destinationFileName";
        
        	imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
        
        	imagejpeg($dst_im, $destinationFileName,100);
        }
        
        

        The url below shows what i mean by bad image quality.
        http://www.micclub.co.uk/v5/arts.php

        it used to be like this:http://www.micclub.co.uk/gallery/pic23.jpg

        Ive had a look at the replies ive had but i cant seem to find what i need. Hope this information will help you to help me. 🙂

        Thanks in advance
        Kam

          Yep, looks like the problem covered in the FAQ.

            The low quality might have something to do with your GD extension.

            GD2 produces much nicer pics when resizing

              Write a Reply...