note 92944 modified in function.imagesetpixel by danbrown

From: Date: Sun, 16 Aug 2009 18:08:48 +0000
Subject: note 92944 modified in function.imagesetpixel by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159552@lists.php.net to get a copy of this message
another gradient example that can do horizontal or vertical gradients <?php $width=$_GET['width']; $height=$_GET['height']; $starts=explode(",",$_GET['startcolor']); $ends=explode(",",$_GET['endcolor']); $rstart=$starts[0]; $gstart=$starts[1]; $bstart=$starts[2]; $rend=$ends[0]; $gend=$ends[1]; $bend=$ends[2]; $r=$rstart; $g=$gstart; $b=$bstart; $bigger=imagecreatetruecolor($width,$height); for ($y=0;$y<=265;$y++) { if ($mode == 'horiz') { //if doing a horizontal gradient, reset to the starting color every row $r=$rstart; $g=$gstart; $b=$bstart; } for ($x=0;$x<=464;$x++) { imagesetpixel($bigger,$x,$y,imagecolorallocate($bigger,$r,$g,$b)); if ($mode=="horiz") { if ($r != $rend) { $r=$r+(($rend-$rstart)/$width); } if ($g != $gend) { $g=$g+(($gend-$gstart)/$width); } if ($b != $bend) { $b=$b+(($bend-$bstart)/$width); } } } if ($mode == "vert") { if ($r != $rend) { $r=$r+(($rend-$rstart)/$height); } if ($g != $gend) { $g=$g+(($gend-$gstart)/$height); } if ($b != $bend) { $b=$b+(($bend-$bstart)/$height); } } } header("Content-type: image/jpeg"); header('Content-Disposition: inline; filename="gradient.jpg"'); imagejpeg($bigger,NULL,99); imagedestroy($bigger); ?> --was-- another gradient example that can do horizontal or vertical gradients <?php $width=$_GET['width']; $height=$_GET['height']; $starts=explode(",",$_GET['startcolor']); $ends=explode(",",$_GET['endcolor']); $rstart=$starts[0]; $gstart=$starts[1]; $bstart=$starts[2]; $rend=$ends[0]; $gend=$ends[1]; $bend=$ends[2]; $r=$rstart; $g=$gstart; $b=$bstart; $bigger=imagecreatetruecolor($width,$height); for ($y=0;$y<=265;$y++) { if ($mode == 'horiz') { //if doing a horizontal gradient, reset to the starting color every row $r=$rstart; $g=$gstart; $b=$bstart; } for ($x=0;$x<=464;$x++) { imagesetpixel($bigger,$x,$y,imagecolorallocate($bigger,$r,$g,$b)); if ($mode=="horiz") { if ($r != $rend) { $r=$r+(($rend-$rstart)/$width); } if ($g != $gend) { $g=$g+(($gend-$gstart)/$width); } if ($b != $bend) { $b=$b+(($bend-$bstart)/$width); } } } if ($mode == "vert") { if ($r != $rend) { $r=$r+(($rend-$rstart)/$height); } if ($g != $gend) { $g=$g+(($gend-$gstart)/$height); } if ($b != $bend) { $b=$b+(($bend-$bstart)/$height); } } } header("Content-type: image/jpeg"); header('Content-Disposition: inline; filename="gradient.jpg"'); imagejpeg($bigger,NULL,99); imagedestroy($bigger); http://php.net/manual/en/function.imagesetpixel.php

« previous php.notes (#159552) next »