Вывод изображения

Статус
Закрыто для дальнейших ответов.

T1m

Новичок
Регистрация
14.03.2009
Сообщения
4
Пишу свой движок сайта для сервера игры Ragnarok Online
Столкнулся с проблемой.
Сделал топ гильдий, но при выводе емблемы, вместо картинки что-то не понятное...



Вот сам модуль топа:

Код:
<?php
ob_start();
session_start();
include("config.php");
if($config_gzip == true)
{
	ob_start("ob_gzhandler");
}
if($config_debug_mode == true)
{
	error_reporting(E_ALL ^ E_NOTICE);
}
else
{
	error_reporting(null);
}
include("functions.php");
$func = new func();
$func->sec();
echo '<span class="content-header">'.$lang['guild_rank_1'].'</span>';
if(empty($_POST['order']))
{
	$order = 'guild_lv';
}
else
{
	$order = $_POST['order'];
}
if(empty($_POST['order2']))
{
	$order2 = 'DESC';
}
else
{
	$order2 = $_POST['order2'];
}
$table = 'guild';
$limit = 50;
$links_limit = 4;
$page = $_GET['page'];
$totalrows = mysql_num_rows(mysql_query("SELECT * FROM `$table`"));
if(empty($page))
{
	$page = '1';
};
$start = ($page-1)*$limit;
$start = round($start,0);
$result = mysql_query("SELECT * FROM `$table` ORDER BY $order $order2 LIMIT $start, $limit");
echo '<br><td width="555px" style="padding-left: 19px; padding-top: 0px;"><table border="1" align="center">
<tr>
	<td align="center"><b>Гильдия</b></td>
	<td align="center"><b>Местер гильдии</b></td>
	<td align="center"><b>Уровень</b></td>
	<td align="center"><b>Сред. ур.</b></td>
	<td align="center"><b>ыыы</b></td>
</tr>';
while ($r = mysql_fetch_array($result))
{
	$master = $r['master'];
	$q1 = mysql_query("SELECT * FROM `char` WHERE `name`='$master'");
	$test = mysql_fetch_array($q1);
	$acc_id = $test['account_id'];
	$q2 = mysql_query("SELECT * FROM login WHERE account_id='$acc_id'");
	$t = mysql_fetch_array($q2);
	if($t['level']>49)
	{
		continue;
	}
	echo '<tr>
	<td width="170px"  align="center">'.$r['name'].'</td>
	<td width="200px"  align="center">'.$r['master'].'</td>
	<td width="70px"  align="center">'.$r['guild_lv'].'</td>
	<td width="70px"  align="center">'.$r['average_lv'].'</td>
	<td width="70px"  align="center"><img src=\"emblem.php"></td>
	</tr>';
};
echo '</table>';
$totalpages = $totalrows / $limit;
$totalpages = ceil($totalpages);
if($page == 1)
{
	$endpage = ($page+$links_limit)-1;
}
else
{
	$endpage = ($page+$links_limit)-2;
	$prevpage = $page-1;
	echo "<a href=\"index.phpmod=guild&page=$prevpage\">".$lang['pag2'].'</a> ';
	echo "<a href=\"index.phpmod=guild&page=$prevpage\">$prevpage</a> ";
}
if($endpage > $totalpages)
{
	$endpage = $totalpages;
}
for($i = $page; $i <= $endpage; $i++)
{
	if($i == $page)
	{
		echo "[$i] ";
	}
	else
	{
		echo "<a href=\"index.phpmod=guild&page=$i\">$i</a> ";
	}
}
if($page != $totalpages)
{
	if($totalpages == 0)
	{
		echo $lang['pag3'];
	}
	else
	{
	$nextpage = $page+1;
	echo "<a href=\"index.phpmod=guild&page=$nextpage\">".$lang['pag1'].'</a> ';
	}
}
echo '<br /><form action="index.phpmod=guild" method="post">
<br>Сортировать топ по:
<select name="order">
<option value="guild_lv" selected="selected">Уровень гильдии</option>
<option value="average_lv">Средний уровень игроков</option>
</select>
<input type="submit" name="Submit" value="Выбрать" />
</form><br />На сервере всего '.$totalrows.'  гильдий.</div></td>';
?>
Вот скрипт на вывод емблемы гильдии:
Код:
<?php
session_start();

function imagecreatefrombmpstring($im) {
	$header = unpack("vtype/Vsize/v2reserved/Voffset", substr($im, 0, 14));
	$info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant", substr($im, 14, 40));
	extract($info);
	extract($header);
	if($type != 0x4D42)
		return false;
	$palette_size = $offset - 54;
	$ncolor = $palette_size / 4;
	$imres=imagecreatetruecolor($width, $height);
	imagealphablending($imres, false);
	imagesavealpha($imres, true);
	$pal=array();
	if($palette_size) {
		$palette = substr($im, 54, $palette_size);
		$gd_palette = "";
		$j = 0; $n = 0;
		while($j < $palette_size) {
			$b = ord($palette{$j++});
			$g = ord($palette{$j++});
			$r = ord($palette{$j++});
			$a = ord($palette{$j++});
			if ( ($r == 255) && ($g == 0) && ($b == 255))
				$a = 127; // alpha = 255 on 0xFF00FF
			$pal[$n++] = imagecolorallocatealpha($imres, $r, $g, $b, $a);
		}
	}
	$scan_line_size = (($bits * $width) + 7) >> 3;
	$scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size & 0x03): 0;
	for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
		$scan_line = substr($im, $offset + (($scan_line_size + $scan_line_align) * $l), $scan_line_size);
		if($bits == 24) {
			$j = 0; $n = 0;
			while($j < $scan_line_size) {
				$b = ord($scan_line{$j++});
				$g = ord($scan_line{$j++});
				$r = ord($scan_line{$j++});
				$a = 0;
				if ( ($r == 255) && ($g == 0) && ($b == 255))
					$a = 127; // alpha = 255 on 0xFF00FF
				$col=imagecolorallocatealpha($imres, $r, $g, $b, $a);
				imagesetpixel($imres, $n++, $i, $col);
			}
		}
		else if($bits == 8) {
			$j = 0;
			while($j < $scan_line_size) {
				$col = $pal[ord($scan_line{$j++})];
				imagesetpixel($imres, $j-1, $i, $col);
			}
		}
		else if($bits == 4) {
			$j = 0; $n = 0;
			while($j < $scan_line_size) {
				$byte = ord($scan_line{$j++});
				$p1 = $byte >> 4;
				$p2 = $byte & 0x0F;
				imagesetpixel($imres, $n++, $i, $pal[$p1]);
				imagesetpixel($imres, $n++, $i, $pal[$p2]);
			}
		}
		else if($bits == 1) {
			$j = 0; $n = 0;
			while($j < $scan_line_size) {
				$byte = ord($scan_line{$j++});
				$p1 = (int) (($byte & 0x80) != 0);
				$p2 = (int) (($byte & 0x40) != 0);
				$p3 = (int) (($byte & 0x20) != 0);
				$p4 = (int) (($byte & 0x10) != 0);
				$p5 = (int) (($byte & 0x08) != 0);
				$p6 = (int) (($byte & 0x04) != 0);
				$p7 = (int) (($byte & 0x02) != 0);
				$p8 = (int) (($byte & 0x01) != 0);
				imagesetpixel($imres, $n++, $i, $pal[$p1]);
				imagesetpixel($imres, $n++, $i, $pal[$p2]);
				imagesetpixel($imres, $n++, $i, $pal[$p3]);
				imagesetpixel($imres, $n++, $i, $pal[$p4]);
				imagesetpixel($imres, $n++, $i, $pal[$p5]);
				imagesetpixel($imres, $n++, $i, $pal[$p6]);
				imagesetpixel($imres, $n++, $i, $pal[$p7]);
				imagesetpixel($imres, $n++, $i, $pal[$p8]);
			}
		}
	}
	return $imres;
}

if (isset($_SESSION['emblems'])) {
	$emblems = $_SESSION['emblems'];
	if ($_GET['data'] && $emblems[$_GET['data']] != "") {
		$ebm = @gzuncompress(pack('H*', $emblems[$_GET['data']]));
		if (function_exists("gd_info")) {
			$im = imagecreatefrombmpstring($ebm);
			header('Content-Type: image/png');
			imagepng($im);
			imagedestroy($im);
		} else {
			header('Content-Type: image/bitmap');
			echo $ebm;
		}
	}
}

if (function_exists("gd_info")) {
	$im  = imagecreate (24, 24); 
	$bgc = imagecolorallocate($im, 0, 0, 0);
	imagefill($im, 0, 0, $bgc);
	header('Content-Type: image/png');
	imagepng($im);
	imagedestroy($im);
} else {
	$in = fopen("/images/no_emblema.bmp", "rb");
	$data = fread($in, 65535);
	header('Content-Type: image/bitmap');
	echo $data;
}
?>
Модуль топа лежит в /mod а файл на вывод емблем лежит в корне сайта.
Не могу понять в чем проблема, помогите пожалуйста :unsure:



--------------------------------------------
Заодно хочу спросить:
Как сделать чтобы некоторые ссылки были видны только после авторизации, а сама форма авторизации проподала?
 

T1m

Новичок
Регистрация
14.03.2009
Сообщения
4
Поправил модуль вывода изображений, всеравно не работает....

Код:
<?

function imagecreatefrombmpstring($im) {
	$header = unpack("vtype/Vsize/v2reserved/Voffset", substr($im,0,14));
	$info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant", substr($im,14,40));

	extract($info);
	extract($header);

	if($type != 0x4D42) return false;		  // signature "BM"

	$palette_size = $offset - 54;
	
	$ncolor = $palette_size / 4;									

	$imres=imagecreatetruecolor($width,$height);
	imagealphablending($imres,false);
	imagesavealpha($imres,true);
	$pal=array();

	if($palette_size) {
		$palette = substr($im, 54, $palette_size);
		$gd_palette = "";
		$j = 0; $n=0;
		while($j < $palette_size) {
			$b = ord($palette{$j++});
			$g = ord($palette{$j++});
			$r = ord($palette{$j++});
			$a = ord($palette{$j++});
			if ( ($r==255) && ($g==0) && ($b==255)) $a=127; // alpha = 255 on 0xFF00FF
			$pal[$n++]=imagecolorallocatealpha($imres, $r, $g, $b, $a);
		}
	}

	$scan_line_size = (($bits * $width) + 7) >> 3;
	$scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size & 0x03): 0;

	for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
		// BMP stores scan lines starting from bottom
		$scan_line = substr($im, $offset + (($scan_line_size + $scan_line_align) * $l), $scan_line_size);
		if($bits == 24) {
			$j = 0; $n=0;
			while($j < $scan_line_size) {
				$b = ord($scan_line{$j++});
				$g = ord($scan_line{$j++});
				$r = ord($scan_line{$j++});
				$a = 0;
				if ( ($r==255) && ($g==0) && ($b==255)) $a=127; // alpha = 255 on 0xFF00FF
				$col=imagecolorallocatealpha($imres, $r, $g, $b, $a);
				imagesetpixel($imres, $n++, $i, $col);
			}
		}
		else if($bits == 8) {
			$j=0;
			while($j<$scan_line_size) {
				$col=$pal[ord($scan_line{$j++})];
				imagesetpixel($imres, $j-1, $i, $col);
			}
		}
		else if($bits == 4) {
			$j = 0; $n=0;
			while($j < $scan_line_size) {
				$byte = ord($scan_line{$j++});
				$p1 = $byte >> 4;
				$p2 = $byte & 0x0F;
				imagesetpixel($imres, $n++, $i, $pal[$p1]);
				imagesetpixel($imres, $n++, $i, $pal[$p2]);
			}
		}
		else if($bits == 1) {
			$j = 0; $n=0;
			while($j < $scan_line_size) {
				$byte = ord($scan_line{$j++});
				$p1 = (int) (($byte & 0x80) != 0);
				$p2 = (int) (($byte & 0x40) != 0);
				$p3 = (int) (($byte & 0x20) != 0);
				$p4 = (int) (($byte & 0x10) != 0);
				$p5 = (int) (($byte & 0x08) != 0);
				$p6 = (int) (($byte & 0x04) != 0);
				$p7 = (int) (($byte & 0x02) != 0);
				$p8 = (int) (($byte & 0x01) != 0);
				imagesetpixel($imres, $n++, $i, $pal[$p1]);
				imagesetpixel($imres, $n++, $i, $pal[$p2]);
				imagesetpixel($imres, $n++, $i, $pal[$p3]);
				imagesetpixel($imres, $n++, $i, $pal[$p4]);
				imagesetpixel($imres, $n++, $i, $pal[$p5]);
				imagesetpixel($imres, $n++, $i, $pal[$p6]);
				imagesetpixel($imres, $n++, $i, $pal[$p7]);
				imagesetpixel($imres, $n++, $i, $pal[$p8]);
			}
		}
	}
	return $imres;
}

if (count($_GET))
{
	if (isset($_GET['id']))
	{
		$mysql = mysql_connect($config_sql_host, $config_sql_user, $config_sql_pass);
		mysql_select_db($db_name) or die('fuck');

		mysql_query("set character_set_client='cp1251'");
		mysql_query("set character_set_results='cp1251'");
		mysql_query("set collation_connection='cp1251_general_ci'");

		$result = mysql_query("SELECT emblem_data FROM `guild` WHERE guild_id='".$_GET['id']."'");

		$res = mysql_fetch_assoc($result);

		if (isset($res["emblem_data"]))
		{
			if ($res["emblem_data"] !== '')
			{
				$arr = explode("_", $res["emblem_data"]);
				$image = implode("/", $arr);
				$image=gzuncompress(pack('H*',$image));

				header('Content-Type: image/png');
				header('Cache-control: cache, store');
				imagepng(imagecreatefrombmpstring($image));
			}
		} else {
			$file_rec=@fopen("images/spacer.gif","r");
			$dt = fgets($file_rec, 43);
			header('Content-Type: image/gif');
			header('Cache-control: cache, store');
			echo $dt;
			
		}
	}
}

?>
 

MeLord

Новичок
Регистрация
23.03.2009
Сообщения
3
Путь к скрипту вывода указывайте так <img scr="../emblem.php"></img>
 
Статус
Закрыто для дальнейших ответов.
Верх Низ