Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Konwersja PNG 24bit 8 kolorów
gsmphone
post
Post #1





Grupa: Zarejestrowani
Postów: 150
Pomógł: 0
Dołączył: 20.10.2006

Ostrzeżenie: (0%)
-----


Witam,

Mam dość nie typowe pytanie. Szukam od wczoraj jak to zrobić ale nigdzie nie mogę znaleźć. Mam plik PNG i jak w locie zmniejszyć mu ilość kolorów z 24bit na 8?

Z góry dziękuję za pomoc

hmmm, chyba nikt nie wie. Czy to się w ogóle da zrobić w php?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




2 minuty szukania:
http://pl.php.net/manual/en/function.imagecreatefrompng.php
Cytat
I had a problem with PNG files.
My source files were PNG-8 files and i wanted to add some drawings to the Image with alpha blending, but it was not possible only by doing imagecolorallocatealpha() and imagefilledellipse() for example.
I noticed that it was only working for PNG-24 images, but i don't want to use them, because they are to big for my website, but PNG-8 files would be much greater.
My result is that the image has to be converted to PNG-24 after loading and converted back to PNG-8 before saving/output.
This is the script:

<?php
// Load Image and get it's size
$size = getimagesize("png8image.png");
$im = imagecreatefrompng("png8image.png");

// Convert the Image to PNG-24
$im_tc = imagecreatetruecolor($size[0],$size[1]);
imagecopy($im_tc,$im,0,0,0,0,$size[0],$size[1]);
imagedestroy($im);

//Now do what ever you want, all alpha-operation do work
$color = imagecolorallocatealpha ($im_tc,255,255,255,75);
imagefilledellipse ($im_tc,10,10,6,4,$color);

//And now convert it back to PNG-8
$im_result = imagecreate($size[0],$size[1]);
imagecopy($im_result,$im_tc,0,0,0,0,$size[0],$size[1]);
imagedestroy($im_tc);


//And save it
imagepng($im_result,"png8image.png");
?>


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
gsmphone
post
Post #3





Grupa: Zarejestrowani
Postów: 150
Pomógł: 0
Dołączył: 20.10.2006

Ostrzeżenie: (0%)
-----


Dziękujęsmile.gif, a jak zrobić to samo tylko z BMP?

Bo z tego co szukałem, ciężko jest to zrobić z BMP aby się grafika nie popsuła.

Ten post edytował gsmphone 6.04.2011, 12:50:34
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 09:10