Barand Posted April 25, 2008 Share Posted April 25, 2008 The only way I get the bgd transparent was to output as gif <?php //GET TYPE (THAT USER WANTS) $type = @$_GET['type']; if ($type == false) { $type = 'top'; } //GET DIMENTIONS (THAT USER WANTS) $height = intval(@$_GET['height']); if ($height == 0) { $height = 800; } $width = intval(@$_GET['width']); if ($width == 0) { $width = 1600; } //GET HEX COLOURS (THAT USER WANTS) $start_colour = $_GET['start_colour']; if ($start_colour == false) { $start_colour = '000000'; } $end_colour = $_GET['end_colour']; if ($end_colour == false) { $end_colour = 'FF0000'; } //CONVERT HEX COLOURS TO RGB $hex_r = substr($start_colour, 0, 2); $hex_g = substr($start_colour, 2, 2); $hex_b = substr($start_colour, 4, 2); $start_r = hexdec($hex_r); $start_g = hexdec($hex_g); $start_b = hexdec($hex_b); $hex_r = substr($end_colour, 0, 2); $hex_g = substr($end_colour, 2, 2); $hex_b = substr($end_colour, 4, 2); $end_r = hexdec($hex_r); $end_g = hexdec($hex_g); $end_b = hexdec($hex_b); //CREATE BLANK IMAGE $image = @imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream"); if ($type == 'top') { //LOOP THROUGH ALL THE PIXELS for($y = 0; $y < $height; $y++) { //LOOP THROUGH ROW for($x=0; $x < $width; $x++) { //CALCULATE THIS ROWS RGB COLOURS if ($start_r == $end_r) { $new_r = $start_r; } $difference = $start_r - $end_r; $new_r = $start_r - intval(($difference / $height) * $y); //==== if ($start_g == $end_g) { $new_g = $start_g; } $difference = $start_g - $end_g; $new_g = $start_g - intval(($difference / $height) * $y); //=== if ($start_b == $end_b) { $new_b = $start_b; } $difference = $start_b - $end_b; $new_b = $start_b - intval(($difference / $height) * $y); //=== //ALLOCATE THE COLOR $row_color = imagecolorresolve($image, $new_r, $new_g, $new_b); //CREATE ROW OF THIS COLOR imagesetpixel($image, $x, $y, $row_color); } } } if ($type == 'left') { //LOOP THROUGH ALL THE PIXELS for($x = 0; $x < $width; $x++) { //LOOP THROUGH COLUMN for($y=0; $y < $height; $y++) { //CALCULATE THIS ROWS RGB COLOURS if ($start_r == $end_r) { $new_r = $start_r; } $difference = $start_r - $end_r; $new_r = $start_r - intval(($difference / $width) * $x); //==== if ($start_g == $end_g) { $new_g = $start_g; } $difference = $start_g - $end_g; $new_g = $start_g - intval(($difference / $width) * $x); //=== if ($start_b == $end_b) { $new_b = $start_b; } $difference = $start_b - $end_b; $new_b = $start_b - intval(($difference / $width) * $x); //=== //ALLOCATE THE COLOR $row_color = imagecolorresolve($image, $new_r, $new_g, $new_b); //CREATE ROW OF THIS COLOR imagesetpixel($image, $x, $y, $row_color); } } } $bgcol = imagecolorallocate($image, 255,255,255); $mask = imagecreate ($width, $height); // mask image $maskbg = imagecolorallocate($mask, 255,255,255); $masktextcol = imagecolorallocate($mask, 0,0,0); imagettftext($mask, 400, 0, 10, 550, $masktextcol, 'c:/windows/fonts/ariblk.ttf', 'Nick'); for ($x=0; $x<$width; $x++) { for ($y=0; $y<$height; $y++) { if (imagecolorat($mask,$x,$y) == $maskbg) { imagesetpixel($image,$x,$y,$bgcol); } } } $small = imagecreate(400,200); imagecopyresampled($small,$image,0,0,0,0,400,200,$width, $height); imagedestroy($mask); imagedestroy($image); $tc = imagecolorat($small, 0, 0); imagecolortransparent($small, $tc); header("content-type: image/gif"); imagegif($small); imagedestroy($small); ?> Link to comment https://forums.phpfreaks.com/topic/102160-solved-gradient-text/page/3/#findComment-527322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.