Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $height = isset($_GET['height']) ? $_GET['height'] : 80;
- $width = isset($_GET['width']) ? $_GET['width'] : 80;
- // top | left
- $dir = isset($_GET['direction']) ? $_GET['direction'] : 'top';
- $start = $_GET['start'];
- $end = $_GET['end'];
- list($r, $g, $b) = hex2rgb($start);
- list($r2, $g2, $b2) = hex2rgb($end);
- $img = imagecreatetruecolor($width, $height);
- $pixel = $dir == 'top' ? $height : $width;
- for($i = 0; $i < $pixel; $i++) {
- $color = imagecolorallocate($img,
- round($r - ($r - $r2)/($pixel-1)*$i),
- round($g - ($g - $g2)/($pixel-1)*$i),
- round($b - ($b - $b2)/($pixel-1)*$i));
- imageline($img,
- $dir == 'top' ? 0 : $i, $dir == 'top' ? $i : 0,
- $dir == 'top' ? $width : $i, $dir == 'top' ? $i : $height,
- $color);
- }
- // output image
- header('Content-Type: image/png');
- imagepng($img);
- imagedestroy($img);
- function hex2rgb($color) {
- return array_map(function($val) {
- return hexdec($val);
- }, str_split($color, 2));
- }
Add Comment
Please, Sign In to add comment