NO

Biblioteca Gd - Exemplos

Por Nostradamus, 17 de set. de 2006 em Tutoriais de Websites

otserv
tibia
5
2.6k
NostradamusN
17 de setembro de 2006 às 15:19

Irei mostrar exemplos como essa poderosa ferramenta que é a Biblioteca GD pode fazer.

Folha

 

<?php$width = 1600;$height = 1200;$canvas = imagecreatetruecolor($width,$height);$white = imagecolorallocate($canvas,255,255,255);imagefill($canvas,0,0,$white);for ($n=1;$n<255;$n++) {	$green[$n] = imagecolorallocatealpha($canvas,0,$n,0,105);}$max = 80000;$p1 = 79;$p2 = 89;$p3 = 98;$x = 0;$y = 0;for ($n=0;$n<$max;$n++) {	$p = rand(0,100);	$xt = $x;	if ($p < $p1) {  $x = (0.85*$x)+(0.04*$y)+0.075;  $y = (-0.04*$xt)+(0.85*$y)+0.18;	} elseif($p < $p2) {  $x = (0.20*$x)-(0.26*$y)+0.4;  $y = (0.23*$xt)+(0.22*$y)+0.045;	} elseif($p < $p3) {  $x = (-0.15*$x)+(0.28*$y)+0.575;  $y = (0.26*$xt)+(0.24*$y)-0.086;	} else {  $x = 0.5;  $y = 0.16*$y;	}	$diameter = rand(1,15);	imagefilledellipse($canvas, $width-($width*$x), $height-($height*$y), $diameter, $diameter, $green[(100*$y)+(155*$x)]);}$i = imagecreatetruecolor($width/2, $height/2);imagecopyresampled($i, $canvas, 0, 0, 0, 0, ($width/2), ($height/2), $width, $height);header("Content-type: image/png");imagepng($i);?>

 

Copie o código e veja o resultado.

Preview:

apo5.th.jpg

Texto com sombra

 

<?php	$title = "XTibia";  //Texto a ser colocado	$source = imagecreatetruecolor(600,36);	$white = imagecolorallocate($source,255,255,255);	imagefill($source,0,0,$white);	$black = imagecolorallocate($source,0,0,0);	imagettftext($source,20,0,2,24,$black,"fontes/BAUHS93.TTF",$title);	$image = gaussian_dropshadow($source);	$black = imagecolorallocate($source,0,0,0);	imagettftext($image,20,0,2,24,$red,"fontes/BAUHS93.TTF",$title);	header("Content-type: image/png");	imagepng($image);	function gaussian_dropshadow($original,$x_offset=4,$y_offset=4,$alpha=80) {  $gauss_fact = array(1,2,4,8,16,24,16,8,4,2,1);  $gauss_width = count($gauss_fact);  $gauss_sum = array_sum($gauss_fact);  $c = 0;  $m_offset = floor($gauss_width/2);  $temp1 = imagecreatetruecolor(imagesx($original)+($m_offset*2),imagesy($original)+($m_offset*2));  $white = imagecolorallocate($temp1,255,255,255);  imagefill($temp1,0,0,$white);  imagecopy($temp1, $original, $m_offset, $m_offset, 0, 0, imagesx($original),imagesy($original));  for ($y=0;$y<imagesy($temp1);$y++) { 	 for ($x=0;$x<imagesx($temp1);$x++) {    $t1 = imagecolorat($temp1,$x,$y);    $p[$x][$y]['r'] = ($t1 >> 16) & 0xFF;    $p[$x][$y]['g'] = ($t1 >> 8) & 0xFF;    $p[$x][$y]['b'] = $t1 & 0xFF;    $p1[$x][$y]['r'] = 255;    $p1[$x][$y]['g'] = 255;    $p1[$x][$y]['b'] = 255; 	 }  }  $sumr=0; $sumg=0; $sumb=0;  $w = imagesx($original);  $h = imagesy($original);  for($i=$m_offset;$i<$w+$m_offset;$i++){    for($j=$m_offset;$j<$h+$m_offset;$j++){ 	 $sumr=0; $sumg=0; $sumb=0; 	 for($k=0;$k<$gauss_width;$k++){    $xt = $i-(($gauss_width-1)>>1)+$k;    $r=$p[$xt][$j]['r'];    $g=$p[$xt][$j]['g'];    $b=$p[$xt][$j]['b'];    $sumr+=$r*$gauss_fact[$k];    $sumg+=$g*$gauss_fact[$k];    $sumb+=$b*$gauss_fact[$k]; 	 } 	  	 $p1[$i][$j]['r'] = $sumr/$gauss_sum; 	 $p1[$i][$j]['g'] = $sumg/$gauss_sum; 	 $p1[$i][$j]['b'] = $sumb/$gauss_sum; 	     }  }  $temp2 = imagecreatetruecolor(imagesx($original),imagesy($original));  $white = imagecolorallocate($temp2,255,255,255);  imagefill($temp2,0,0,$white);  $w = imagesx($temp2);  $h = imagesy($temp2);  for($i=$m_offset;$i<$w+$m_offset;$i++){    for($j=$m_offset;$j<$h+$m_offset;$j++){ 	 $sumr=0; $sumg=0; $sumb=0; 	 for($k=0;$k<$gauss_width;$k++){    $xy = $j-(($gauss_width-1)>>1)+$k;    $r=$p1[$i][$xy]['r'];    $g=$p1[$i][$xy]['g'];    $b=$p1[$i][$xy]['b'];    $sumr+=$r*$gauss_fact[$k];    $sumg+=$g*$gauss_fact[$k];    $sumb+=$b*$gauss_fact[$k]; 	 } 	 $col = imagecolorallocatealpha($temp2,$sumr/$gauss_sum,$sumg/$gauss_sum,$sumb/$gauss_sum,$alpha); 	 imagesetpixel($temp2,$i-$m_offset+$x_offset,$j-$m_offset+$y_offset,$col);    }  }    return $temp2;	}?>

 

No caso eu usei a fonte BAUHS93.TFF encontrada na pasta fontes.

Baixe ela clicando aqui.

Preview

corel011dv0.jpg

Atualizarei assim que fazer mais.

Editado Outubro 13 por Nostradamus

Conde do Monte CristoC
17 de setembro de 2006 às 16:42

oÔ, OMG IS MAGNIFICT! CONGRATULATIONS ! (My english is Umrrivel)

colexC
17 de setembro de 2006 às 20:47

ficou muito bom o resultado

gostei do code :D

NostradamusN
21 de setembro de 2006 às 22:22

Lista atualizada.

Editado Setembro 21 por Nostradamus

1 mês depois...
DemulidorD
10 de outubro de 2006 às 23:31

nice man....