imagecopyresize() just skips pixels in order to reduce it in size.
imagecopyresampled() will take the average of adjacent pixels and
therefore produce a much better scaled down image.

-Rasmus

On Sun, 25 Aug 2002, Jason Reid wrote:

> If you have GD2 I'd advise using imagecopyresampled, as I found using
> imagecopyresized often resulted in blue or grayish images, while
> imagecopyresampled resulted in normal looking images.
>
> Jason Reid
> [EMAIL PROTECTED]
> --
> AC Host Canada
> www.achost.ca
>
> ----- Original Message -----
> From: "Dave at Sinewaves.net" <[EMAIL PROTECTED]>
> To: "Arcadius A." <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Sunday, August 25, 2002 12:23 PM
> Subject: RE: [PHP] GD lib. image quality!
>
>
> > imageCreate will create an image, but its palette will be very limited, so
> > when you try to copy your photo onto it, it will maintain the palette of
> the
> > original picture.  Obviously, this is not what you want, since the picture
> > comes out looking all grey and faded (probably 8-16 colors!).
> >
> > What works for me is creating a blank image using imageCreate(), then
> saving
> > it as a temporary jpeg (using imageJpeg). This action will set the palette
> > of the image to a jpeg's palette (close to 16-bit or better colorspace).
> If
> > you imageCopyResized over this temp.jpg (which you need to create whenever
> > you run the script to ensure sizing is perfect), it will come out with the
> > full palette of colors.
> >
> > Pseudo code:
> > <?
> > $dest_h = whatever your calculated destination height is;
> > $dest_w = whatever your calculated destination width is;
> >
> > $src_h = height of original image;
> > $src_w = width of original image;
> >
> >    // create the blank limited-palette image
> > $base_image = imageCreate($dest_w, $dest_h);
> >
> >    // convert and save it to temp.jpg
> > imagejpeg($base_image, 'path/to/temp.jpg');
> >
> >    // get the image pointer to the temp jpeg
> > $image = imageCreateFromJpeg('path/to/temp.jpg');
> >
> >    // get the image pointer to the original image
> > $imageToResize = imageCreateFromJpeg('path/to/image_to_be_resized.jpg');
> >
> >    // resize the original image over temp.jpg
> >    // since you have GD2, you could also use imageCopyResampled
> > imageCopyResized($image, $imageToResize, 0, 0, 0, 0, $dest_w, $dest_h,
> > $src_w, $src_h);
> >
> >    // values for output jpeg quality
> > $jpegQuality = 75;
> >
> >    // create the resized image
> > imageJpeg($image, 'path/to/thumbnail_name.jpg', $jpegQuality);
> > ?>
> >
> >
> > Then all you have to do is a little cleanup with imageDestroy() and you
> > should have a nice looking thumbnail!
> >
> >
> > I usually add a line like this to the script to make sure everything went
> > smoothly:
> > <?
> > echo '<html><head><title>Thumbnail Generator</title>'
> >     .'</head><body><img src="path/to/thumbnail_name.jpg">'
> >     .'</body></html>';
> > ?>
> >
> > It lets me see the quality of the thumbnail the second the script
> completes.
> >
> >
> > Try it - you'll get perfect thumbnails every time.  I used this technique
> > for all of the pictures at www.arkestraclandestina.com with GD1.6 - and
> all
> > of them actually had custom color profiles!  Works like a charm.
> >
> > I like this method because I can be sure that the script won't break on
> > sites with older PHP and GD versions - which is an important consideration
> > when you're deploying applications to other sites...
> >
> > However!  If you are sure it will only be run on a PHP4, GD2 system, you
> can
> > avoid all of the temp jpg madness altogether by just altering your code to
> > use imageCreateTrueColor() instead of imageCreate()!!  ;P  Easy as pie!
> >
> > Dave
> >
> >
> >
> > -----Original Message-----
> > From: Arcadius A. [mailto:[EMAIL PROTECTED]]
> > Sent: Sunday, August 25, 2002 4:11 AM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] GD lib. image quality!
> >
> >
> > Hello!
> > I wrote a little script for generation thumbnails of larger images....
> > <code>
> > $origImage = imageCreateFromJpeg($sourcePath."/".$currentImageName);
> >     $thumbnail = imageCreate($thumbWidth,$thumbHeight);// create empty
> image
> >
> >
> imageCopyResized($thumbnail,$origImage,0,0,0,0,$thumbWidth,$thumbHeight,imag
> > esX($origImage),imagesY($origImage));
> >     imageJpeg($thumbnail, $targetPath."/".$thumbNamePrefix."_thumb.jpg");
> //
> > Store it
> >     imageDestroy($thumbnail); // cleanup
> >     echo "<br>Image ".$targetPath."/".$thumbNamePrefix."_thumb.jpg"."
> > created successfully!";
> >
> > </code>
> >
> > then, I've noticed that the quality of the thumbnails created is very bad!
> > my "phpinfo()" page shows  "2.0 or higher" as GD version
> >
> > So, I'm wondering whether I'm doing something wrong in my code or whether
> > there exist a better library to use with PHP ... a library able to
> generate
> > good quality JPG files...
> >
> > Thanks in advance.
> >
> > Arcadius.
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to