[PHP] Convert Crests

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
gio
Posts: 186
Joined: Fri Apr 13, 2007 1:40 am
Contact:

[PHP] Convert Crests

Post by gio »

Hey guys,

I try to Convert crests to PNG files to show them on my website.
I got this script ready but it shows you wrong colors (blue and black only):

Code: Select all

<?  if(!empty($_GET['clan_crest'])){	$name = 'Crest';	$crest = $_GET['clan_crest'];	}else if(!empty($_GET['ally_crest'])){	$name = 'AllyCrest';	$crest = $_GET['ally_crest'];	}else	die('No Crest!');  $file = fopen('ftp://localhost/crests/'.$name.'_'.$crest.'.bmp', 'rb'); //fopen($filename,'rb'); $dds = fread($file,4);  if ($dds!=='DDS ') die("Error: no hay imagen DDS");  //DDS header $hdrSize = readInt($file); $hdrFlags = readInt($file); $imgHeight = readInt($file)-4; $imgWidth = readInt($file); $imgPitch = readShort($file);   //DXT1 header fseek($file, 84); $dxt1 = fread($file,4); if ($dxt1!=='DXT1') die("Error: no es formato DX1");  //here we go fseek($file, 128); header ("Content-type: image/png"); $img=imagecreatetruecolor($imgWidth,$imgHeight);  for ($y=-1; $y<$imgHeight/4; $y++) {   for ($x=0; $x<$imgWidth/4; $x++)   {     $color0_16 = readShort($file);     $color1_16 = readShort($file);     $r0 = ($color0_16 >> 11) << 3;     $g0 = (($color0_16 >> 5) & 63) << 2;     $b0 = ($color0_16 & 31) << 3;     $r1 = ($color1_16 >> 11) << 3;     $g1 = (($color1_16 >> 5) & 63) << 2;     $b1 = ($color1_16 & 31) << 3;     $color0_32 = imagecolorallocate($img,$r0,$g0,$b0);     $color1_32 = imagecolorallocate($img,$r1,$g1,$b1);     $color01_32 = imagecolorallocate($img,$r0/2+$r1/2,$g0/2+$g1/2,$b0/2+$b1/2);     $black = imagecolorallocate($img,0,0,0);     $data = readInt($file);     for ($yy=0;$yy<4;$yy++)     {       for ($xx=0;$xx<4;$xx++)       {         $bb = $data & 3;         $data = $data >> 2;         switch ($bb)         {           case 0: $c = $color0_32; break;           case 1: $c = $color1_32; break;           case 2: $c = $color01_32; break;           default: $c = $black; break;         }         imagesetpixel($img,$x*4+$xx,$y*4+$yy,$c);       }     }   } }   imagepng($img);   ## Functions needed function readInt($file) {   $b4 = ord(fgetc($file));   $b3 = ord(fgetc($file));   $b2 = ord(fgetc($file));   $b1 = ord(fgetc($file));   return ($b1<<24)|($b2<<16)|($b3<<Cool)|$b4; }   function readShort($file) {   $b2 = ord(fgetc($file));   $b1 = ord(fgetc($file));   return ($b1<<Cool)|$b2; }  ?> 
I hope someone could help me with that..
regards
gio

PS: We have to convert from DDS to PNG..
---
L2J = Convert.ToL2J(L2off);
---
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: [PHP] Convert Crests

Post by janiii »

try with fopen mode 'r' only
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
gio
Posts: 186
Joined: Fri Apr 13, 2007 1:40 am
Contact:

Re: [PHP] Convert Crests

Post by gio »

this doesn't change anything.. :/
The access to the files is not the problem..
but thx for reply..
---
L2J = Convert.ToL2J(L2off);
---
gio
Posts: 186
Joined: Fri Apr 13, 2007 1:40 am
Contact:

Re: [PHP] Convert Crests

Post by gio »

Ok i fixed it..
Here it is for everyone ;)

Code: Select all

<?  if(!empty($_GET['clan_crest'])){	$name = 'Crest';	$crest = $_GET['clan_crest'];	}else if(!empty($_GET['ally_crest'])){	$name = 'AllyCrest';	$crest = $_GET['ally_crest'];	}else	die('No Crest!');  $file = fopen('ftp://localhost/'.$name.'_'.$crest.'.bmp', 'r'); //fopen($filename,'rb'); $dds = fread($file,4);  if ($dds!=='DDS ') die("Error: no hay imagen DDS");  //DDS header $hdrSize = readInt($file); $hdrFlags = readInt($file); $imgHeight = readInt($file)-4; $imgWidth = readInt($file); $imgPitch = readShort($file);   //DXT1 header fseek($file, 84); $dxt1 = fread($file,4); if ($dxt1!=='DXT1') die("Error: no es formato DX1");  //here we go fseek($file, 128); header ("Content-type: image/png"); $img=imagecreatetruecolor($imgWidth,$imgHeight);  for ($y=-1; $y<$imgHeight/4; $y++) {   for ($x=0; $x<$imgWidth/4; $x++)   {     $color0_16 = readShort($file);     $color1_16 = readShort($file);     $r0 = ($color0_16 >> 11) << 3;     $g0 = (($color0_16 >> 5) & 63) << 2;     $b0 = ($color0_16 & 31) << 3;     $r1 = ($color1_16 >> 11) << 3;     $g1 = (($color1_16 >> 5) & 63) << 2;     $b1 = ($color1_16 & 31) << 3;     $color0_32 = imagecolorallocate($img,$r0,$g0,$b0);     $color1_32 = imagecolorallocate($img,$r1,$g1,$b1);     $color01_32 = imagecolorallocate($img,$r0/2+$r1/2,$g0/2+$g1/2,$b0/2+$b1/2);     $black = imagecolorallocate($img,0,0,0);     $data = readInt($file);     for ($yy=0;$yy<4;$yy++)     {       for ($xx=0;$xx<4;$xx++)       {         $bb = $data & 3;         $data = $data >> 2;         switch ($bb)         {           case 0: $c = $color0_32; break;           case 1: $c = $color1_32; break;           case 2: $c = $color01_32; break;           default: $c = $black; break;         }         imagesetpixel($img,$x*4+$xx,$y*4+$yy,$c);       }     }   } }   imagepng($img);   ## Functions needed function readInt($file) {   $b4 = ord(fgetc($file));   $b3 = ord(fgetc($file));   $b2 = ord(fgetc($file));   $b1 = ord(fgetc($file));   return ($b1<<24)|($b2<<16)|($b3<<8)|$b4; }   function readShort($file) {   $b2 = ord(fgetc($file));   $b1 = ord(fgetc($file));   return ($b1<<8)|$b2; }  ?> 
using:
crest.php?clan_crest=1234568789
or
crest.php?ally_crest=1234568789

have fun
gio

ps: maybe some fixes needed.. its not clean code i know but it works :D
---
L2J = Convert.ToL2J(L2off);
---
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: [PHP] Convert Crests

Post by janiii »

could you maybe also post it to the thread where it is used (where you did not get your answer and created a new thread for it)? thx.
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
wiseelf
Posts: 62
Joined: Thu May 07, 2009 7:11 pm

Re: [PHP] Convert Crests

Post by wiseelf »

very usefull thanks
I use google translate.
Delux
Posts: 4
Joined: Fri Apr 02, 2010 4:04 pm

Re: [PHP] Convert Crests

Post by Delux »

wiseelf wrote:very usefull thanks
i need to use http://mysite.com/crest.php?ally_crest=1234568789 ?
Post Reply