php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23491 Very bad Quality when I use imagecopyresized
Submitted: 2003-05-05 07:57 UTC Modified: 2003-05-13 01:43 UTC
From: ab at berg dot net Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.3.2RC2 OS: RedHat Linux 7.0 with gd-1.8.4-9
Private report: No CVE-ID: None
 [2003-05-05 07:57 UTC] ab at berg dot net
Hello,

when I use the function imagecopyresized with the PHP Version 4.3.1 or 4.3.2RC2 the new Image has a very bad quality.
If use the PGP Version 4.2.3 it works very fast and with good quality.

For example:
Original Image: http://www.andreas.boehm.de/1/ori.JPG
Image with 4.2.3: http://www.andreas.boehm.de/1/good.jpg
Image with 4.3.x: http://www.andreas.boehm.de/1/bad.jpg

I have install the GD-Lib 1.8.4-9 and my configure command for the version 4.2.3 and 4.3.x is:
'./configure' '--with-mysql' '--with-gd' '--with-apxs' '--with-jpeg-dir' '--with-png-dir' '--with-zlib-dir' '--enable-track-vars=yes' '--enable-url-includes=yes' '--with-tiff-dir' '--with-pdflib' '--enable-shared-pdflib' '--with-ttf' '--with-imap' '--with-kerberos' '--with-imap-ssl' '--with-gettext' '--enable-ftp'

Please help me - Thank you
Andreas

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-05 08:11 UTC] derick@php.net
Post a link to your code please.

Derick
 [2003-05-05 08:51 UTC] ab at berg dot net
Hi Derick,

here my thumbnail-function:

function imgthumb($ori,$thump,$thumbQuality,$thumbWidth)
{
    $origImageHandle = ImageCreateFromJPEG($ori);

    $imageWidth = imagesx($origImageHandle);
    $imageHeigth = imagesy($origImageHandle);

    $thumbHeigth = floor($thumbWidth * $imageHeigth / $imageWidth);
    $thumbImageHandle = ImageCreate("$thumbWidth","$thumbHeigth");

    imagecopyresized($thumbImageHandle,$origImageHandle,0,0,0,0,$thumbWidth,$thumbHeigth,imagesx($origImageHandle),imagesy($origImageHandle));
    imagejpeg($thumbImageHandle,$thump,"$thumbQuality");
}

Thx for your fast answer
Andreas
 [2003-05-05 09:22 UTC] rasmus@php.net
gd-1.x only supports 256 colours.  You should be using the bundled version of gd2 and then ImageCreateTrueColor() instead of ImageCreate() in your code.  Then the thumbnail would look nice.
 [2003-05-05 09:26 UTC] rasmus@php.net
Actually, never mind, just took a look at your images.  I assume you were also using gd-1.8 with PHP 4.2.3?
 [2003-05-05 09:36 UTC] ab at berg dot net
Hi Rasmus,

really? Why works the thumbnail function with php 4.2.3 and gd 1.8.x perfectly with more than 256 colours and with php 4.3.x not?

How can I compile the GD2 bundled?
What must I change in my configure command?

Thanks a lot
Andreas
 [2003-05-05 16:39 UTC] sniper@php.net
Please provide a complete example script which actually
produces the result you show here.

 [2003-05-06 00:49 UTC] ab at berg dot net
Hi Sniper,

i use the function:
function imgthumb($ori,$thump,$thumbQuality,$thumbWidth)
{
    $origImageHandle = ImageCreateFromJPEG($ori);

    $imageWidth = imagesx($origImageHandle);
    $imageHeigth = imagesy($origImageHandle);

    $thumbHeigth = floor($thumbWidth * $imageHeigth / $imageWidth);
    $thumbImageHandle = ImageCreate("$thumbWidth","$thumbHeigth");

   
imagecopyresized($thumbImageHandle,$origImageHandle,0,0,0,0,$thumbWidth,
$thumbHeigth,imagesx($origImageHandle),imagesy($origImageHandle));
    imagejpeg($thumbImageHandle,$thump,"$thumbQuality");
}

And this are the example Images:
Original Image: http://www.andreas.boehm.de/1/ori.JPG
Image with 4.2.3: http://www.andreas.boehm.de/1/good.jpg
Image with 4.3.x: http://www.andreas.boehm.de/1/bad.jpg

Andreas
 [2003-05-06 18:35 UTC] sniper@php.net
Please provide a _COMPLETE_ example script.




 [2003-05-07 13:24 UTC] ab at berg dot net
Hi Sniper,

This ist the Script online: http://www.andreas.boehm.de/1/thumb.phtml

And the Source-Code is:
<-- snip -->
<?

imgthumb("ori.JPG","thumb.jpg","65","150");
echo "<img src=thumb.jpg>";

// Erstellt ein Thumbnail
function imgthumb($ori,$thump,$thumbQuality,$thumbWidth)
{
    // Function die aus einem JPEG-Bild ein
    // kleineres Bild erzeugt.
    //    $ori   = Pfad der Originaldatei
    //    $thump = Pfad des kleinen Bilds

    $origImageHandle = ImageCreateFromJPEG($ori);

    $imageWidth = imagesx($origImageHandle);
    $imageHeigth = imagesy($origImageHandle);

    $thumbHeigth = floor($thumbWidth * $imageHeigth / $imageWidth);
    $thumbImageHandle = ImageCreate("$thumbWidth","$thumbHeigth");

    imagecopyresized($thumbImageHandle,$origImageHandle,0,0,0,0,$thumbWidth,$thumbHeigth,imagesx($origImageHandle),imagesy($origImageHandle));
    
    imagejpeg($thumbImageHandle,$thump,"$thumbQuality");
}

?>
<-- snap -->


At the moment the Script works perfectly - i have installed the PHP Version 4.2.3.
If I install 4.3.x with the same script would be very bad like: http://www.andreas.boehm.de/1/bad.jpg

Bye
Andreas
 [2003-05-07 20:40 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

If you change ImageCreate() to ImageCreateTrueColor() the images instantly become nice & clear. For the record I have tested this php 4.2.3 linked against the native GD library 2.0+ the results were the same.
 [2003-05-08 02:49 UTC] ab at berg dot net
Ok,

but my problim is who can I use the "the native GD library 2.0+ "

with this configure Command:
'./configure' '--with-mysql' '--with-gd' '--with-apxs' '--with-jpeg-dir'
'--with-png-dir' '--with-zlib-dir' '--enable-track-vars=yes'
'--enable-url-includes=yes' '--with-tiff-dir' '--with-pdflib'
'--enable-shared-pdflib' '--with-ttf' '--with-imap' '--with-kerberos'
'--with-imap-ssl' '--with-gettext' '--enable-ftp'
 [2003-05-13 01:43 UTC] ab at berg dot net
can me somebody help?
thanks
Andreas
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 02:01:35 2024 UTC