Jump to content


Photo

Transformar Imagem.


  • Faça o login para participar
10 replies to this topic

#1 TTC_VeNdEdOr

TTC_VeNdEdOr

    Curioso

  • Usuários
  • 433 posts
  • Sexo:Masculino
  • Localidade:João Pessoa - PB

Posted 12/06/2008, 14:15

Pessoal, tenho um script que ja consegui pronto na internet, ele cria dados em cima de uma imagem como no exemplo abaixo:

http://www.ageofempi...mp;ladder=AoCRM

Como eu posso fazer com que esse endereço vire uma figura png?


igz_sign.pgp

<?php

/**
 * CIGZSignature
 * IGZones.com Implementation
 * @autor jose @ www.t1poder.com.ar - www.aocgroup.com.ar
 * @data Agoust, 2007
 * @param string $_GET['nick'] nick of the player
 * @param string $_GET['ladder'] Ladder ID
 * @param string $_GET['country'] Country ID
 **/

$nick=$_GET['nick'];
$ladder=$_GET['ladder'];
$country=$_GET['country'];

 
class CIGZSignature
{
	var $strBuffer;
	var $nick;
	var $ladderID;
	
	/**
	 * Constructor
	 *
	 * @param string $nick 
	 * @param string $roomId
	 **/
	function CIGZSignature ($nick, $ladderID, $country)
	{
		$this->country = trim ($country);
		$this->nick = $this->cleanUserName (trim ($nick));
		$this->ladderID = $ladderID;
		
		$ladders = array (
			'AoCRM', /* default value */
			'AoCDM',
			'AoCCS',
			'AoKDM',
			'AoKRM',
			'AoKCS',
			'RoRRM',
			'AoERM'
		);
		if (array_search ($this->ladderID, $ladders) === FALSE)
		{
			$this->ladderID = $ladders[0];
		}
		
		$this->cache_file = 'cache/' . $this->nick . "-" . $this->ladderID . '.txt';
	}
	
	function cleanUserName ($nick)
	{
		$tag = '';
		if ($nick[0] == '[')
		{
			$end = strpos ($nick, ']') + 1;
			$nick = substr ($nick, $end);
		}
		return $nick;
	}
	/**
	 * 	
	 * Read Ratings Info from IGZ
	 * 
	 **/
	function getRatings ()
	{
		$this->buffer = '';
		
		if ($this->nick == '')
		{
			$this->parsedData = array ();
			return;
		}
	
		if (file_exists ($this->cache_file))
		{
			if ((filemtime ($this->cache_file) + 21600) > time ())
			{
				$fp = fopen ($this->cache_file, 'r');
				$this->buffer = fread ($fp, 8096);
				fclose ($fp);
			}
		}
		
		if ($this->buffer == '')
		{
			$host = "www.igzones.com";
			$headers = "GET /ratingservices?ladder=%s&player=%s&getclan=1 HTTP/1.0\r\nHost: %s\r\n\r\n";
			
			$strHeaders = sprintf ($headers, $this->ladderID, $this->nick, $host);
				
			$socket = @fsockopen($host, 80, $errNo, $errStr, 30);
			
			if ($socket)
			{
				@socket_set_blocking ($socket, FALSE);
				@fwrite ($socket, $strHeaders);
			}
				
			while (!@feof ($socket)) 
			{
				$this->buffer .= @fgets ($socket, 8192);
			}	
			if ($socket)
			{
				@fclose ($socket);
			}
			
			$initStr = strpos ($this->buffer, "\r\n\r\n");
			$this->buffer = trim (substr ($this->buffer, $initStr));
			
			$fp = fopen ($this->cache_file, 'w');
			fwrite ($fp, $this->buffer);
			fclose ($fp);
		}
		$this->parseData ();
	}
	
	/**
	 * Data Parser
	 **/
	function parseData ()
	{
		$playerInfo = split (",", $this->buffer);
		
		/**
		 *
		 **/
		/* 
		1,eXecute,1818,28,5,1,-1,AoCDM; 
		8 elements
		
		FuriX Development Team,FuriX,1,eXecute,1818,28,5,1,-1,AoCDM;
		10 elemetns
		*/
		
		if (count ($playerInfo) == 8) //without clan info
		{
			$pInfo = array (
				'nick' => $playerInfo[1],
				'rating' => $playerInfo[2],
				'games' => ($playerInfo[3] + $playerInfo[4]),
				'winper' => sprintf ("%.2f", @($playerInfo[3]/($playerInfo[3] + $playerInfo[4])) * 100),
				'wins' => $playerInfo[3],
				'losses' => $playerInfo[4],
				'inc' => $playerInfo[5],
				'streak' => $playerInfo[6],
				'tag' => ''
			);
		}
		elseif (count ($playerInfo) == 10) // with Clan Info
		{
			$pInfo = array (
				'nick' => $playerInfo[3],
				'rating' => $playerInfo[4],
				'games' => ($playerInfo[5] + $playerInfo[6]),
				'winper' => sprintf ("%.2f", @($playerInfo[5]/($playerInfo[5] + $playerInfo[6])) * 100),
				'wins' => $playerInfo[5],
				'losses' => $playerInfo[6],
				'inc' => $playerInfo[7],
				'streak' => $playerInfo[8],
				'tag' => $playerInfo[1]
			);
		}
		else
		{
			$pInfo = array ();
		}
	
		$this->parsedData = $pInfo;
	}
	/**
	 * Build Signature
	 **/
	function showSignature ()
	{
		header ("Content-type: image/png"); 
		$im = imagecreatefromgif ("firma.gif"); 
		$black = imagecolorallocate ($im, 255, 255, 255); 
		$white = imagecolorallocate ($im, 255, 255, 255); 
		
		if (count ($this->parsedData) > 0)
		{
			if ($this->parsedData['tag'] != '')
			{
				$this->nick = '[' . $this->parsedData['tag'] . ']' . $this->parsedData['nick'];
			}
			else
			{
				$this->nick = $this->parsedData['nick'];
			}
			if ($this->country != '' && function_exists ('imagecreatefromgif'))
			{
				$imFlag = @imagecreatefromgif ('images/flags/' . strtolower ($this->country) . '.gif');
				if (is_resource ($imFlag))
				{
					imagecopy ($im, $imFlag, 47, 7, 0, 0, 18, 12);
					$this->nick = "   " . $this->nick;
					imagedestroy ($imFlag);
				}
			}
				
			$this->parsedData['winpercent'] = sprintf ("%.2f", @$this->parsedData['wins'] / $this->parsedData['games'] * 100);
			$ratingLine1 = "Games: " . $this->parsedData['games']." - Win: " . $this->parsedData['winpercent'] . "%";
			$ratingLine2 = "Wins: " . $this->parsedData['wins'] . " - Losses: " . $this->parsedData['losses'] . " - Inc: " . $this->parsedData['inc'] .  " - IGZ:" . $this->ladderID;
	
			$rating = "Rating: " . $this->parsedData['rating'];
			imagestring ($im, 3, 305 - imagefontwidth (4) * strlen ($rating), 6, $rating, $white);
			imagestring ($im, 4, 43, 5, $this->nick, $white); 
			imagestring ($im, 4, 42, 5, $this->nick, $white); 
			imagestring ($im, 2, 49, 25, $ratingLine1, $white);  
			imagestring ($im, 2, 49, 25, $ratingLine1, $white);  
			imagestring ($im, 2, 49, 35, $ratingLine2, $white); 
			imagestring ($im, 2, 49, 35, $ratingLine2, $white); 		
		}
		else
		{
			imagestring ($im, 2, 110, 20, "No Rating Information", $white);  
		}
		imagepng ($im);
		imagedestroy ($im);
	}
}

$signature = new CIGZSignature ($_GET['nick'], $_GET['laddder'], $_GET['country']);
$signature->getRatings ();
$signature->showSignature ();
?>

Obrigado.
Age of Empires III - www.ageofempires3.com.br
Age of Empires II - www.ageofempires2.com.br
NÃO RECOMENDO: Levei calote da hospedagem BRWebs, assim que paguei cancelaram e não devolveram :/

#2 fly2k

fly2k

    Super Veterano

  • Usuários
  • 2262 posts
  • Sexo:Não informado

Posted 12/06/2008, 14:48

Ele já é uma imagem PNG não?
Quer aprender PHP? -> www.manjaphp.com.br
Tutoriais, código colaborativo (pastebin), curso de PHP, artigos e etc.

#3 TTC_VeNdEdOr

TTC_VeNdEdOr

    Curioso

  • Usuários
  • 433 posts
  • Sexo:Masculino
  • Localidade:João Pessoa - PB

Posted 12/06/2008, 15:12

é sim, so que pra vc ver os dados ja inseridos na imagem o link da imagem fica assim:

http://www.ageofempi...mp;ladder=AoCRM

eu preciso que fique assim por exemplo: http://www.ageofempi...mp;ladder=AoCRM.png
Age of Empires III - www.ageofempires3.com.br
Age of Empires II - www.ageofempires2.com.br
NÃO RECOMENDO: Levei calote da hospedagem BRWebs, assim que paguei cancelaram e não devolveram :/

#4 Maykel Esser

Maykel Esser

    Super Veterano

  • Usuários
  • 1536 posts
  • Sexo:Masculino
  • Localidade:Curitiba - PR

Posted 12/06/2008, 15:40

nunca vi cassos que dê certo colocar extensão em query string...
porque vc nao oferece a URL real da imagem logo abaixo dela?

Se este post lhe ajudou, ajude o fórum também. Use a reputação de mensagens! add.png


#5 TTC_VeNdEdOr

TTC_VeNdEdOr

    Curioso

  • Usuários
  • 433 posts
  • Sexo:Masculino
  • Localidade:João Pessoa - PB

Posted 13/06/2008, 10:44

Como assim?

Essas imagens são pra ser usadas como assinaturas nos foruns ou ate mesmo serem usadas no orkut, entao eu preciso que elas sejam em extensao real de imagem (gif, jpg, png...)
Age of Empires III - www.ageofempires3.com.br
Age of Empires II - www.ageofempires2.com.br
NÃO RECOMENDO: Levei calote da hospedagem BRWebs, assim que paguei cancelaram e não devolveram :/

#6 fly2k

fly2k

    Super Veterano

  • Usuários
  • 2262 posts
  • Sexo:Não informado

Posted 13/06/2008, 15:51

BOm... tente ... após o

header ("Content-type: image/png");

Colocar

header('Content-Disposition: attachment; filename="imagem.png"');
Quer aprender PHP? -> www.manjaphp.com.br
Tutoriais, código colaborativo (pastebin), curso de PHP, artigos e etc.

#7 savior

savior

    Campanha [codebox], use ou morra :D

  • Usuários
  • 1229 posts
  • Sexo:Masculino
  • Localidade:Curitiba, PR - Brasil
  • Interesses:Na vida ;P

Posted 13/06/2008, 16:47

@fly2k
Isso iria gerar um download da imagem :unsure:
Creio que não é isto que ele deseja.

Ele tem que ver antes de ele enviar alguma header tem algum output de string, etc...

[]'s

[lastfm] [blog]

Campanha codebox: use-a ou morra!
bfmaster_duran[at]yahoo.com.br


#8 DarkSign

DarkSign

    Doutor

  • Usuários
  • 868 posts
  • Sexo:Masculino
  • Localidade:Brasil
  • Interesses:Tecnologias na área WEB em geral e desenvolvimento.

Posted 13/06/2008, 17:01

Gente, eu acho que o cara soh quer que a imagem resultante daquele código todo seja salva em PNG, ou seja, alguma função do GD que faça isso.
Por exemplo, no meu caso, seria uma imagem pra download que, no site n tem logo nenhum e assim que faz o download, na verdade o sistema altera a imagem adicionando o logo, mas n sei como salvar essa img modificada, que eh o mesmo caso.

/*DarkSign*/
Não sabe por onde começar? Que tal pelas Regras ?

#9 TTC_VeNdEdOr

TTC_VeNdEdOr

    Curioso

  • Usuários
  • 433 posts
  • Sexo:Masculino
  • Localidade:João Pessoa - PB

Posted 13/06/2008, 18:49

exato, as informacoes da imagem sao dinamicas ajustadas automaticamente, por isso nao da pra fazer o download da imagem pq assim ficaria fixo.

Vejam so na imagem: http://www.ageofempi...mp;ladder=AoCRM

tem um "Rating" ele é atualizado la automaticamente a medida que o jogador perde ou ganha pontos...

Mas se eu for em qualquer forum, e clicar la em painel de controle, la em assinatura, e colocar esse link como imagem ( http://www.ageofempi...mp;ladder=AoCRM ) o forum nao vai aceitar pq o link nao tem extensao de imagem entende?
Age of Empires III - www.ageofempires3.com.br
Age of Empires II - www.ageofempires2.com.br
NÃO RECOMENDO: Levei calote da hospedagem BRWebs, assim que paguei cancelaram e não devolveram :/

#10 fly2k

fly2k

    Super Veterano

  • Usuários
  • 2262 posts
  • Sexo:Não informado

Posted 16/06/2008, 16:59

seguinte....então vc vai ter que usar URL AMIGÁVEIS!

Pesquise esse termo!
Quer aprender PHP? -> www.manjaphp.com.br
Tutoriais, código colaborativo (pastebin), curso de PHP, artigos e etc.

#11 MarcoviZ

MarcoviZ

    ubuntu for human being

  • Usuários
  • 1137 posts
  • Sexo:Não informado

Posted 18/06/2008, 14:22

putz, ou então vc cria uma pasta para cada pessoa...
ai vc poe o nome da pasta de
imagem.png
e o arquivo que cria com o nome de index dentro da pagina

funciona :P

té+
[]'s




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq