Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][gd] imagecolorset a PNG, JPEG
lord_t
post
Post #1





Grupa: Zarejestrowani
Postów: 603
Pomógł: 131
Dołączył: 24.07.2007
Skąd: Górny Śląsk

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


Elo,

chciałem napisać prosty skrypt, który zmienia jeden kolor na obrazku na inny, napisałem go dla JPG, ale nie działał. Przerobiłem na PNG i znów. Na necie znalazłem prawie identyczny kod, ale dla gifów - ten działa.

Czy ta funkcja nie obsługuje PNG, JPEG?
Jeśli tak to czemu nie?

Znacie jakieś sposoby, żeby ta funkcja zadziałała? Oprócz przerabiania najpierw wszystkiego na gifa.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Blame
post
Post #2





Grupa: Zarejestrowani
Postów: 678
Pomógł: 124
Dołączył: 26.09.2009

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


http://lmgtfy.com/?q=gd+color+replacement I pierwszy lepszy skrypt:
  1. function html2rgb($input)
  2. {
  3. $input=($input[0]=="#")?substr($input, 1,6):substr($input, 0,6);
  4. return array(
  5. 'r'=>hexdec( substr($input, 0, 2) ),
  6. 'g'=>hexdec( substr($input, 2, 2) ),
  7. 'b'=>hexdec( substr($input, 4, 2) )
  8. );
  9. }
  10. function colorReplace($image,$oldcolor,$newcolor=false)
  11. {
  12. //make the colors rbg
  13. $rgbold = html2rgb($oldcolor);
  14. //make the old color transparant
  15. $oldcolor = imagecolorallocate($image, $rgbold[r], $rgbold[g], $rgbold[b]);
  16. imagecolortransparent($image, $oldcolor);
  17. if($newcolor)
  18. {
  19. $rgbnew = html2rgb($newcolor);
  20. //make a new image in the new color
  21. $newimage = imagecreatetruecolor(imagesx($image), imagesy($image));
  22. //color the new image
  23. $newcolor = imagecolorallocate($image,$rgbnew[r], $rgbnew[g], $rgbnew[b]);
  24. imagefill($newimage, 0, 0, $newcolor);
  25.  
  26. //paste the old image on the new colored image
  27. imagecopymerge($newimage,$image,0,0,0,0, imagesx($image), imagesy($image), 100);
  28. imagecopymerge($image,$newimage,0,0,0,0, imagesx($image), imagesy($image), 100);
  29. imagedestroy($newimage);
  30. }
  31. }

Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 9.10.2025 - 09:12