Guest User

Untitled

a guest
Dec 7th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. $height = isset($_GET['height']) ? $_GET['height'] : 80;
  4. $width = isset($_GET['width']) ? $_GET['width'] : 80;
  5. // top | left
  6. $dir = isset($_GET['direction']) ? $_GET['direction'] : 'top';
  7. $start = $_GET['start'];
  8. $end = $_GET['end'];
  9.  
  10. list($r, $g, $b) = hex2rgb($start);
  11. list($r2, $g2, $b2) = hex2rgb($end);
  12.  
  13. $img = imagecreatetruecolor($width, $height);
  14. $pixel = $dir == 'top' ? $height : $width;
  15. for($i = 0; $i < $pixel; $i++) {
  16. $color = imagecolorallocate($img,
  17. round($r - ($r - $r2)/($pixel-1)*$i),
  18. round($g - ($g - $g2)/($pixel-1)*$i),
  19. round($b - ($b - $b2)/($pixel-1)*$i));
  20. imageline($img,
  21. $dir == 'top' ? 0 : $i, $dir == 'top' ? $i : 0,
  22. $dir == 'top' ? $width : $i, $dir == 'top' ? $i : $height,
  23. $color);
  24. }
  25.  
  26. // output image
  27. header('Content-Type: image/png');
  28. imagepng($img);
  29. imagedestroy($img);
  30.  
  31.  
  32. function hex2rgb($color) {
  33. return array_map(function($val) {
  34. return hexdec($val);
  35. }, str_split($color, 2));
  36. }
Add Comment
Please, Sign In to add comment