<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EntreBits &#187; scripts</title>
	<atom:link href="http://rd.entrebits.com.mx/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://rd.entrebits.com.mx</link>
	<description>Lo que dejo entre bits.</description>
	<lastBuildDate>Mon, 02 Jan 2012 09:44:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Barras de progreso dinámicas en PHP</title>
		<link>http://rd.entrebits.com.mx/2008/03/20/barras-de-progreso-dinamicas-en-php/</link>
		<comments>http://rd.entrebits.com.mx/2008/03/20/barras-de-progreso-dinamicas-en-php/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 09:12:00 +0000</pubDate>
		<dc:creator>Rodrigo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://rd.entrebits.com.mx/2008/03/20/barras-de-progreso-dinamicas-en-php/</guid>
		<description><![CDATA[Bueno, hace unos días que empecé a jugar un poco con la librería GD y PHP, y a la hora de desarollar un sitio, mientras más recicles código es mucho mejor. En esta ocasión hice un pequeño script para crear... ]]></description>
			<content:encoded><![CDATA[<p>Bueno, hace unos días que empecé a jugar un poco con la librería GD y PHP, y a la hora de desarollar un sitio, mientras más recicles código es mucho mejor. En esta ocasión hice un pequeño script para crear barras de progreso dinámicas con PHP, este es un ejemplo: <img src="http://rd.entrebits.com.mx/wp-content/image_bar.php?width=50&amp;palet=0/102/153" alt="Barra de progreso 50% llena" /><br />
La imagen que usé de fondo es esta:  <img src="http://rd.entrebits.com.mx/wp-content/fondo.png" alt="fondo.png" /><code>&lt;?php<br />
/*  variables del porcentaje de largo que queremos mostrar lleno y la paleta de colores en formato RGB (ej: image_bar.php?width=50&amp;palet=0/102/53*/<br />
$width = $_GET['width'];<br />
$palet = $_GET['palet'];<br />
/* verificamos la variable palet que guarda la paleta de colores y separamos los colores RGB*/<br />
if ($palet)<br />
{<br />
$arr_palet = split('/',$palet);<br />
$arraycolor[0] = array($arr_palet[0],	$arr_palet[1],	$arr_palet[2]);<br />
for($i = 1; $i &lt; 9; $i++)<br />
{<br />
if (($arr_palet[0] + 10) &gt; 255) $arr_palet[0] = 255;<br />
else $arr_palet[0] = $arr_palet[0] + 10;<br />
if (($arr_palet[1] + 10) &gt; 255) $arr_palet[1] = 255;<br />
else $arr_palet[1] = $arr_palet[1] + 10;<br />
if (($arr_palet[2] + 10) &gt; 255) $arr_palet[2] = 255;<br />
else $arr_palet[2] = $arr_palet[2] + 10;<br />
$arraycolor[$i] = array($arr_palet[0],	$arr_palet[1],	$arr_palet[2]);<br />
}<br />
}<br />
$data = ($width * 48 / 100);<br />
$data = round($data);<br />
/* Crear imagen a partir de otra*/<br />
$background = @imagecreatefrompng ('fondo.png');<br />
if ($data &gt; 1)<br />
{<br />
$fill1 = imagecreatetruecolor($data,1);<br />
$fill2 = imagecreatetruecolor($data,1);<br />
$fill3 = imagecreatetruecolor($data,1);<br />
$fill4 = imagecreatetruecolor($data,1);<br />
$fill5 = imagecreatetruecolor($data,1);<br />
$fill6 = imagecreatetruecolor($data,1);<br />
	$fill7 = imagecreatetruecolor($data,1);<br />
	$fill8 = imagecreatetruecolor($data,1);<br />
	$fill9 = imagecreatetruecolor($data,1);<br />
	$colors = array(<br />
						array(<br />
								array('62','125','179'),	array('72','133','184'),	array('82','140','190'),<br />
								array('93','149','195'),	array('103','157','200'),	array('114','165','206'),<br />
								array('127','174','211'),	array('135','182','216'),	array('190','190','221')<br />
							),<br />
						array(<br />
								array('181','59','59'),		array('189','69','69'),		array('191','80','80'),<br />
								array('197','90','90'),		array('202','101','101'),	array('208','111','111'),<br />
								array('213','121','121'),	array('218','132','132'),	array('223','142','142')<br />
							),<br />
						array(<br />
								array('10','60','70'),		array('20','70','80'),		array('30','80','90'),<br />
								array('40','90','100'),		array('50','101','110'),	array('60','111','120'),<br />
								array('70','121','130'),	array('80','132','140'),	array('90','142','150')<br />
							),<br />
							$arraycolor<br />
					);<br />
	/* creamos los colores a usar */<br />
	$c1 = imagecolorallocate($fill1, $colors[$color][0][0], $colors[$color][0][1], $colors[$color][0][2]); //Background<br />
	$c2 = imagecolorallocate($fill2, $colors[$color][1][0], $colors[$color][1][1], $colors[$color][1][2]); //Background<br />
	$c3 = imagecolorallocate($fill3, $colors[$color][2][0], $colors[$color][2][1], $colors[$color][2][2]); //Background<br />
	$c4 = imagecolorallocate($fill4, $colors[$color][3][0], $colors[$color][3][1], $colors[$color][3][2]); //Background<br />
	$c5 = imagecolorallocate($fill5, $colors[$color][4][0], $colors[$color][4][1], $colors[$color][4][2]); //Background<br />
	$c6 = imagecolorallocate($fill6, $colors[$color][5][0], $colors[$color][5][1], $colors[$color][5][2]); //Background<br />
	$c7 = imagecolorallocate($fill7, $colors[$color][6][0], $colors[$color][6][1], $colors[$color][6][2]); //Background<br />
	$c8 = imagecolorallocate($fill8, $colors[$color][7][0], $colors[$color][7][1], $colors[$color][7][2]); //Background<br />
	$c9 = imagecolorallocate($fill9, $colors[$color][8][0], $colors[$color][8][1], $colors[$color][8][2]); //Background<br />
	/* formamos el degradado */<br />
	imagefilledrectangle($fill1, 0, 0, $data, 1, $c1);<br />
	imagefilledrectangle($fill2, 0, 0, $data, 1, $c2);<br />
	imagefilledrectangle($fill3, 0, 0, $data, 1, $c3);<br />
	imagefilledrectangle($fill4, 0, 0, $data, 1, $c4);<br />
	imagefilledrectangle($fill5, 0, 0, $data, 1, $c5);<br />
	imagefilledrectangle($fill6, 0, 0, $data, 1, $c6);<br />
	imagefilledrectangle($fill7, 0, 0, $data, 1, $c7);<br />
	imagefilledrectangle($fill8, 0, 0, $data, 1, $c8);<br />
	imagefilledrectangle($fill9, 0, 0, $data, 1, $c9);<br />
	/* formamos la barra de progreso*/<br />
	imagecopy($background,$fill1,1,9,0,0,$data,1);<br />
	imagecopy($background,$fill2,1,8,0,0,$data,1);<br />
	imagecopy($background,$fill3,1,7,0,0,$data,1);<br />
	imagecopy($background,$fill4,1,6,0,0,$data,1);<br />
	imagecopy($background,$fill5,1,5,0,0,$data,1);<br />
	imagecopy($background,$fill6,1,4,0,0,$data,1);<br />
	imagecopy($background,$fill7,1,3,0,0,$data,1);<br />
	imagecopy($background,$fill8,1,2,0,0,$data,1);<br />
	imagecopy($background,$fill9,1,1,0,0,$data,1);<br />
}<br />
/* mandamos las cabeceras, el archivo es una imagen*/<br />
header("Content-type: image/png");<br />
/* mandamos la imagen */<br />
imagepng($background);<br />
?></code></p>
<pre>
Modo de uso:
image_bar.php?width=porcentaje&#038;palet=R/G/B
</pre>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://rd.entrebits.com.mx/2008/03/20/barras-de-progreso-dinamicas-en-php/&via=entrebitsmx&text=Barras de progreso dinámicas en PHP&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://rd.entrebits.com.mx/2008/03/20/barras-de-progreso-dinamicas-en-php/&via=entrebitsmx&text=Barras de progreso dinámicas en PHP&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rd.entrebits.com.mx/2008/03/20/barras-de-progreso-dinamicas-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

