All pastes #174111 Raw Edit

Miscellany

public php v1 · immutable
·published 2006-09-17 16:45 UTC
rendered paste body
<?phpfunction ProgressBar($percentage) {	$width = 160;	$height = 15;		$image = ImageCreate($width,$height);	$img2 = ImageCreate($width,$height);	$back = ImageColorAllocateAlpha($image,255,255,255,127);	$blur = ImageColorAllocate($image,255,0,0);	$fill = ImageColorAllocate($image,0,192,0);	$black = ImageColorAllocate($image,0,0,0);	$white = ImageColorAllocate($image,255,255,255);	ImagePaletteCopy($img2,$image);	ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);	ImageFilledRectangle($img2,0,0,$width-1,$height-1,$back);	$radius = 5;		$startX = ($blockwidth+$spacing)*$i + 1;	ImageRectangleWithRoundedCorners($image, $startX, 1, $startX+$width-1, $height-2, $radius, $blur);	ImageRectangleWithRoundedCorners($img2, $startX, 1, $startX+$width-1, $height-2, $radius, $fill);	$barwidth = ($percentage/100)*$width;	$barwidth += floor($barwidth/$width)*$spacing+1;	ImageCopy( $image, $img2, 0, 0, 0, 0, $barwidth, $height );	ImageDestroy($img2);		$gradient = Gradient(imagesy($image), imagesx($image), "000000", "FFFFFF");		ImageSaveAlpha($image, true);		ImageCopy($image, $gradient, 0, 0, 0, 0, imagesx($image), imagesy($image));		ImagePNG($image);		ImageDestroy($image);}function ImageRectangleWithRoundedCorners(&$im, $x1, $y1, $x2, $y2, $radius, $color) {	ImageFilledRectangle($im, $x1+$radius, $y1, $x2-$radius, $y2, $color);	ImageFilledRectangle($im, $x1, $y1+$radius, $x2, $y2-$radius, $color);	ImageFilledEllipse($im, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color);	ImageFilledEllipse($im, $x2-$radius-($radius/100), $y1+$radius, $radius*2, $radius*2, $color);	ImageFilledEllipse($im, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color);	ImageFilledEllipse($im, $x2-$radius-($radius/100)	, $y2-$radius, $radius*2, $radius*2, $color);}Function Gradient($height,$width,$base,$end, $alpha=50) {	$im = ImageCreate($width,$height);	sscanf($base, "%2x%2x%2x", $rbase, $gbase, $bbase);	sscanf($end, "%2x%2x%2x", $rend, $gend, $bend);	$varstep=$height;	if ($rbase==$rend) {		$rend = $rend -1;	}	if ($gbase==$gend) {		$gend = $gend -1;	}	if ($bbase==$bend) {		$bend = $bend -1;	}	if ($varstep == 0) {		$varstep=1;	}	$rmod = ($rend - $rbase) /$varstep;	$gmod = ($gend - $gbase) /$varstep;	$bmod = ($bend - $bbase) /$varstep;	$white=ImageColorAllocateAlpha($im,255,255,255,$alpha);	for($i=1;$i<$varstep;$i=$i+2) {		$clour1 = ($i*$rmod)+$rbase;		$clour2 = ($i*$gmod)+$gbase;		$clour3 = ($i*$bmod)+$bbase;		$col=ImageColorAllocateAlpha($im,$clour1,$clour2,$clour3,$alpha);		imagefilledrectangle($im,$width-$width+1,$height-$i,$width,$height-$i+1,$col);	}	return $im;}?>