Coding graphical progress bar in php (overlay issue)

巧了我就是萌 提交于 2019-12-11 09:27:28

问题


So far I have the background working, and I have the % bubble floating on top of the bar working. Everything went smoothly using the PHP/GD functions.

But I can't figure out how to add the yellow part. I mean, I could overlay solid color easily. But how would I go in showing that progress bar with vertical stripes, gradients, rounded border and inner shadows?


回答1:


Actually, I found an example using php, javascript, and html here, you can also use the jquery implementation here. And here is a simple one I made in html and css here .

Edit

Actually, there is a way.

PHP/GD

PHP Code

<?php  
// set the type of data (Content-Type) to PNG image  
header("Content-Type: image/png");  

// extract GET global array  
extract($_GET);  

// set defaults  
if(! isset($max)) $max = 100;  
if(! isset($val)) $val = 100;  

// this method prepare blank true color image with given width and height  
$im = imagecreatetruecolor(400, 20);  

// set background color (light-blue)  
$c_bg = imagecolorallocate($im, 222, 236, 247);  
// set foreground color (dark-blue)  
$c_fg = imagecolorallocate($im, 27, 120, 179);  

// calculate the width of bar indicator  
$val_w = round(($val * 397) / $max);  

// create a rectangle for background and append to the image  
imagefilledrectangle($im, 0, 0, 400, 20, $c_bg);  
// create a rectangle for the indicator and appent to the image  
imagefilledrectangle($im, 2, 2, $val_w, 17, $c_fg);  

// render the image as a PNG  
imagepng($im);  

// finally destroy image resources  
imagedestroy($im);  
?>   

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  
<title>PHP GD-Progress Bar</title>  
</head>  

<body>  

    <img src="progressbar.php?max=100&val=70" />  

</body>  

</html>  


来源:https://stackoverflow.com/questions/15988559/coding-graphical-progress-bar-in-php-overlay-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!