imagetruecolortopalette returns a max of 128 colors
imagetruecolortopalette returns a max of 128 colors
am 30.12.2007 22:04:44 von Vegethalia
Dear all,
I'm sure that im doing something wrong, but I can't imagine what!
My problem is the following:
I create an image using imagecreatetruecolor, and, after some
painting, I push the resulting image to the client in 256 colors:
imagetruecolortopalette($this->m_oIMG, false, 256);
header("Content-type: image/png");
if(!imagepng($this->m_oIMG)) echo("Error Creating Image!!!");
The problem is that the resulting image never contain more that 128
colors! I can't push the 24bit image because of the size, as the
images are pretty big.
As you may imagine, the final image quality is quite horrible, for an
example,
http://eqsearchpro.pleyhades.com/ShowRecipe.php?item=8668&re cipe=26059
save the image and open it with photoshop (for instance...), after
that, count the colors.
Any ideas? :)
Thx for your time,
Vegethalia.
Re: imagetruecolortopalette returns a max of 128 colors
am 31.12.2007 22:44:12 von Tim Roberts
Vegethalia wrote:
>
>I'm sure that im doing something wrong, but I can't imagine what!
>My problem is the following:
>
>I create an image using imagecreatetruecolor, and, after some
>painting, I push the resulting image to the client in 256 colors:
>imagetruecolortopalette($this->m_oIMG, false, 256);
>header("Content-type: image/png");
>if(!imagepng($this->m_oIMG)) echo("Error Creating Image!!!");
>
>The problem is that the resulting image never contain more that 128
>colors! I can't push the 24bit image because of the size, as the
>images are pretty big.
24-bit images are only three times larger than 8-bit images. The image on
your page is only 150k bytes; 450k is not that big.
>As you may imagine, the final image quality is quite horrible, for an
>example,
>http://eqsearchpro.pleyhades.com/ShowRecipe.php?item=8668&r ecipe=26059
>save the image and open it with photoshop (for instance...), after
>that, count the colors.
I don't think that image looks bad. If you want smooth coloring, than keep
it as true color.
>Any ideas? :)
The "imagetruecolortopalette" page in the PHP documentation mentions an
alternative. If you know which 256 colors you want, create an empty image
with the palette you want, and use imagecopy to copy into that image.
If you eventually want a palettized image, why don't you create it as
palettized to begin with? Converting a true-color image to palettized is
an expensive operation.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Re: imagetruecolortopalette returns a max of 128 colors
am 02.01.2008 15:54:34 von Vegethalia
First of all, thx for your reply! :)
> >The problem is that the resulting image never contain more that 128
> >colors! I can't push the 24bit image because of the size, as the
> >images are pretty big.
>
> 24-bit images are only three times larger than 8-bit images. =A0The image =
on
> your page is only 150k bytes; 450k is not that big.
>
Uh... well that could be true if you work with 'raw' images, but PNG
images are compressed...
in fact, the previous image (2.450x812 pixels) as a PNG24 needs
870kbytes (and as a bmp uncompressed, almost 6megs!)
> >As you may imagine, the final image quality is quite horrible, for an
> >example,
> >http://eqsearchpro.pleyhades.com/ShowRecipe.php?item=3D8668 &recipe=3D2605=
9
> >save the image and open it with photoshop (for instance...), after
> >that, count the colors.
>
> I don't think that image looks bad. =A0If you want smooth coloring, than k=
eep
> it as true color.
>
> The "imagetruecolortopalette" page in the PHP documentation mentions an
> alternative. =A0If you know which 256 colors you want, create an empty ima=
ge
> with the palette you want, and use imagecopy to copy into that image.
Um I will try this and ill tell you the results.... :)
Anyway, you know why when you tell imagetrucolortopalette to use a
certain number of colors (ie 64), it never uses as much? Is that a bug
or just an nonperfect algorithm?
Thx again,
Vegethalia.
Re: imagetruecolortopalette returns a max of 128 colors
am 03.01.2008 08:19:51 von Tim Roberts
Vegethalia wrote:
>
>Anyway, you know why when you tell imagetrucolortopalette to use a
>certain number of colors (ie 64), it never uses as much? Is that a bug
>or just an nonperfect algorithm?
The beauty of a system like PHP is that you can download the source and
look at it yourself.
The process of identifying an "ideal" 8-bit palette for a true-color image
is surprisingly complicated. Most palettized displays don't actually have
256 colors available (a few dozen are almost always reserved for system
use), so perhaps they optimized it for 128. However, I'm just pulling that
from thin air.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.