Home > Archive > PHP Language > July 2004 > Poor quality on resized images
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Poor quality on resized images
|
|
| Dag Eilertsen 2004-07-06, 8:56 pm |
| The script below resizes images into two different sizes. My problem is that
the quality of the resized images is poor. Any idea how to improve my
script? The users are only uploading jpg's.
Thanks!
Dag Eilertsen
________________________________________
____________________________________
_
$bilde = "./" .$lagringssti .$filnavn1;
$pic = @imagecreatefromjpeg($bilde) or die("Sorry!");
if ($pic)
{
// Make thumb
$width = imagesx($pic);
$height = imagesy($pic);
$twidth = 100;
$theight = $twidth * $height / $width; // Regner ut høyden
$thumb = @imagecreatetruecolor ($twidth, $theight) or die ("Can't
resize!");
imagecopyresized($thumb, $pic, 0, 0, 0, 0, $twidth, $theight, $width,
$height); // Resize to thumb
imagegammacorrect($thumb, 1.0, 1.5);
ImageJPEG($thumb,$lagringssti .basename($filnavn1,'.jpg')
.."_thmb.jpg",100); // JPEG of thumb
// Make small image
$twidth = 230; // Vidde satt til 230 pixler
$theight = $twidth * $height / $width; // Regner ut høyden
$mediumPic = @imagecreatetruecolor ($twidth, $theight) or die ("Can't
change size");
imagecopyresized($mediumPic, $pic, 0, 0, 0, 0, $twidth, $theight, $width,
$height);
imageJPEG($mediumPic,$lagringssti .basename($filnavn1,'.jpg')
.."_small.jpg",100);
imagedestroy($thumb);
imagedestroy($mediumPic);
// Delete the original file
list($stamme, $extension) = split("\.", $filnavn1);
unlink($lagringssti .basename($filnavn1));
} // End: if ($pic)
| |
| gridlock 2004-07-07, 3:56 am |
| Try using the imagecopyresampled() function instead of the
imagecopyresized() - it worked a whole lot better for me
"Dag Eilertsen" <dag.erik.eilertsen@broadpark.no> wrote in message
news:40eb2aca$1@news.broadpark.no...
> The script below resizes images into two different sizes. My problem is
that
> the quality of the resized images is poor. Any idea how to improve my
> script? The users are only uploading jpg's.
>
> Thanks!
> Dag Eilertsen
>
________________________________________
____________________________________[col
or=darkred]
> _
>
> $bilde = "./" .$lagringssti .$filnavn1;
> $pic = @imagecreatefromjpeg($bilde) or die("Sorry!");
> if ($pic)
> {
> // Make thumb
> $width = imagesx($pic);
> $height = imagesy($pic);
> $twidth = 100;
> $theight = $twidth * $height / $width; // Regner ut høyden
>
> $thumb = @imagecreatetruecolor ($twidth, $theight) or die ("Can't
> resize!");
> imagecopyresized($thumb, $pic, 0, 0, 0, 0, $twidth, $theight, $width,
> $height); // Resize to thumb
> imagegammacorrect($thumb, 1.0, 1.5);
>
> ImageJPEG($thumb,$lagringssti .basename($filnavn1,'.jpg')
> ."_thmb.jpg",100); // JPEG of thumb
>
> // Make small image
> $twidth = 230; // Vidde satt til 230 pixler
> $theight = $twidth * $height / $width; // Regner ut høyden
> $mediumPic = @imagecreatetruecolor ($twidth, $theight) or die ("Can't
> change size");
> imagecopyresized($mediumPic, $pic, 0, 0, 0, 0, $twidth, $theight,[/color]
$width,
> $height);
>
> imageJPEG($mediumPic,$lagringssti .basename($filnavn1,'.jpg')
> ."_small.jpg",100);
>
> imagedestroy($thumb);
> imagedestroy($mediumPic);
>
> // Delete the original file
> list($stamme, $extension) = split("\.", $filnavn1);
>
> unlink($lagringssti .basename($filnavn1));
>
> } // End: if ($pic)
>
>
|
|
|
|
|