Scripts

Img2Pix

Dit is gewoon een probeer script. alles word aangepast in de eerste 10 regels. Voorbeeld heb ik niet, ik hoop dat de mensen van phpclub.nl mijn script willen hosten. Als voorbeeld gebruikte ik deze foto: http://www.dark.uwhost2.net/scripts/img2pix/img.jpg Met de standaard instellingen

img2pix
[code]<?php
error_reporting(E_ALL);
$cfg = array();
$cfg['img'] = 'img.jpg'; // plaats van de foto
$cfg['perpix_v'] = 1; // per hoeveel pixels kijkt hij (verticaal)
$cfg['perpix_h'] = 1; // per hoeveel pixels kijkt hij (horizontaal)
$cfg['size'] = 5; // Symbool grootte in px
$cfg['symbol'] = 'M'; // Welk symbool gebruikt hij voor een pixel
$cfg['bg'] =  ''; // Achtergrond kleur in hex, FALSE voor geen achtergrond
function getstream($filename){
	if(@imagecreatefromgif($filename)){
		return imagecreatefromgif($filename);	
	}
	elseif(@imagecreatefromjpeg($filename)){
		return imagecreatefromjpeg($filename);	
	}
	elseif(@imagecreatefrompng($filename)){
		return imagecreatefrompng($filename);	
	}
	elseif(@imagecreatefromwbmp($filename)){
		return imagecreatefromwbmp($filename);	
	}
}
function rgb2hex($r, $g, $b){
   if($r < 0 || $r > 255 || !is_numeric($r)) { $r = 0; }
   if($g < 0 || $g > 255 || !is_numeric($g)) { $g = 0; }
   if($b < 0 || $b > 255 || !is_numeric($b)) { $b = 0; }
   $color = array($r, $g, $b);
   $hexcolor = "#" . sprintf("%02X", $r) . sprintf("%02X", $g) . sprintf("%02X", $b);
   return $hexcolor; 
}  
$stream=getstream($cfg['img']);
?>
<html>
	<head>
		<title>Dotted version of <?=$cfg['img'];?></title>
		<style type="text/css">
		body{
			font-size: <?=$cfg['size'];?>px;
			<?=($cfg['bg'] != FALSE)?'background-color: '.$cfg['bg'].';':'';?>
		}
		</style>
	</head>
<body>
<?php
for($b=0;$b<imagesy($stream)/$cfg['perpix_h'];$b++){
	for($a=0;$a<imagesx($stream)/$cfg['perpix_v'];$a++){
		$rgb=imagecolorat($stream, $a * $cfg['perpix_h'], $b * $cfg['perpix_v']);
		$rgb=array((($rgb >> 16) & 0xFF), (($rgb >> 8) & 0xFF), ($rgb & 0xFF));
		echo '<font color="'.rgb2hex($rgb[0], $rgb[1], $rgb[2]).'">'.$cfg['symbol'].'</font>';
	}
	echo '<br>';
}
?>
</body>
</html>[/code]

Reacties

0
Nog geen reacties.