Guest User

Untitled

a guest
Jun 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2. header("Content-type: image/png");
  3. $c = $_GET['color'];
  4. if(!isset($_GET['color'])) $c = "#COR PADRAO AQUI";
  5. function HexParaRGB($hex) {
  6. $hex = ereg_replace("#", "", $hex);
  7. $cor = array();
  8.  
  9. if(strlen($hex) == 3) {
  10. $cor['r'] = hexdec(substr($hex, 0, 1) . $r);
  11. $cor['g'] = hexdec(substr($hex, 1, 1) . $g);
  12. $cor['b'] = hexdec(substr($hex, 2, 1) . $B);
  13.  
  14. }elseif(strlen($hex) == 6) {
  15. $cor['r'] = hexdec(substr($hex, 0, 2));
  16. $cor['g'] = hexdec(substr($hex, 2, 2));
  17. $cor['b'] = hexdec(substr($hex, 4, 2));
  18. }
  19. return $cor;
  20. }
  21.  
  22. $im = imagecreatefrompng("puffle.png");
  23. $x = 0;
  24. $y = 0;
  25. $lar = imagesx($im);
  26. $alt = imagesy($im);
  27.  
  28. for ($x=0;$x<=$lar;$x++){
  29. for ($y=0;$y<=$alt;$y++){
  30. $rgb = imagecolorat($im, $x, $y);
  31. $r = ($rgb >> 16) & 0xFF;
  32. $g = ($rgb >> 8) & 0xFF;
  33. $b = $rgb & 0xFF;
  34. $cor = $r.'-'.$g.'-'.$b;
  35.  
  36. if($cor == '0-0-255'){
  37. $corHex = HexParaRGB($c);
  38. $color = imagecolorallocate($im, $corHex['r'], $corHex['g'], $corHex['b']);
  39. imagesetpixel($im, $x, $y, $color);
  40. }
  41. }
  42. }
  43.  
  44. imagepng($im);
  45. imagedestroy($im);
  46. ?>
Add Comment
Please, Sign In to add comment