Anonymní profil peter – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil peter – Programujte.comAnonymní profil peter – Programujte.com

 

Příspěvky odeslané z IP adresy 2001:718:2601:26c:dc3b:7d...–

peter
PHP › php imagecolorat - prilis po…
18. 12. 2015   #207406

Tak, muzu dat i zjednodusenou verzi a pro RGB (v komentu pokus pro imagemagic, uprava +-n na +n, upvrava pokus o prepsani funkci chr; ale on chce na prepis funkci a imagemagick instalovat cosi, coz se mi nechce).
1920x1200 rgb, zpracovano za 23s, komprese gzip 40/69 = 58%

<?php
ini_set('max_execution_time', 10000);	//10000s
set_time_limit(10000);   
ini_set('memory_limit', '256M');

function microtime_float()	//pp 17.3.2014
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
$time = array();
$time[] = microtime_float();

function timePrint($time)
{
$time[] = microtime_float();
$t = array();
$t[] = round($time[count($time)-1]-$time[0],3);
for ($i=1;$i<count($time);$i++)
	{
	$t[] = round($time[$i]-$time[$i-1],3);
	}
$t = implode(" | ",$t);
echo '<hr>Cas zpracovani '.$t.' s';
}



function transf(&$img,$w,$h)//&$imagick
{
$out = array('','','');
$c   = array(0,0,0);
$tmp = array(0,0,0);
$tbl = array();
$n = 256;
$nn = $n>>1;
$m = 0;
for ($i=0,$j=-$n;$i<$n;++$i,++$j)
	{

	$tbl[$j] = chr($i);
	$tbl[$i] = chr($i);
/*
	$m = $i<$nn ? $i : $n-1-$i;
	$tbl[$j] = chr($m);
	$tbl[$i] = chr($m);
*/
	}
ksort($tbl);
//$a = 0;
//$iterator = $imagick->getPixelIterator();
$pixel = 0;
for ($j=0;$j<$h;++$j)
	{
	for ($i=0;$i<$w;++$i)
		{
		$pixel = imagecolorat($img, $i, $j);
//return '';
		$c[2] = $pixel & 0xFF;
		$c[1] = ($pixel >> 8) & 0xFF;
		$c[0] = ($pixel >> 16) & 0xFF;
		$out[0] .= $tbl[$c[0]-$tmp[0]];
		$out[1] .= $tbl[$c[1]-$tmp[1]];
		$out[2] .= $tbl[$c[2]-$tmp[2]];
		$tmp[0] = $c[0];
		$tmp[1] = $c[1];
		$tmp[2] = $c[2];
		}
	}
/*
for ($j=0;$j<$h;++$j)
	{
	for ($i=0;$i<$w;++$i)
		{
		$pixel = imagecolorat($img, $i, $j);

foreach($iterator as $row => $pixels)
	{
	foreach ($pixels as $column => $pixel)
		{
var_dump($pixel);
	$iterator->syncIterator();
return '';
*/
return $out[0].$out[1].$out[2];
}

/*
<?php
$imagick = new Imagick("my_image.jpeg");
$iterator = $imagick->getPixelIterator();

foreach($iterator as $row => $pixels) {
    foreach ($pixels as $column => $pixel) {
        // Do something with $pixel
    }
    $iterator->syncIterator();
}
?>
*/



$name1 = "img/jp-bwgirl.jpeg";	//
$name1 = "img/tropical-island-hut.jpg";	//
//$name1 = "img/jp-bwgirl-2.jpeg";	//
$name2 = "tmp/xxx";	//
$bool = file_exists($name1);
echo 'Soubor '.$name1.' '. ($bool ? 'existuje' : 'chyba neexistuje').'<br>';
$b = filesize($name1);

$img = imagecreatefromjpeg($name1);
$w = imagesx($img);
$h = imagesy($img);
//$imagick = new Imagick($name1);
//$w = $imagick->getImageWidth();
//$h = $imagick->getImageHeight();

//var_dump($img);
//imagexbm($img, 'simpletext.xbm');
//header('Content-Type: image/vnd.wap.wbmp');
//imagewbmp($img,$name2);
////header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
////image2wbmp($img);

$b = $w*$h*3;
$out = '';
$out = transf($img,$w,$h);
imagedestroy($img);




$a = 0;
$out = gzcompress($out,9);	

$file2 = fopen($name2, "wb");
fwrite($file2,$out);
fclose($file2);

$a = strlen($out);	unset($out);
echo '<br>out / in =  floor(10000*$a/$b)/100 % gzip';
echo '<br>'.$a. ' / '. $b .' = '.(floor(10000*$a/$b)/100).'% gzip';
echo '<br>'.$w. ' x '. $h .' = '.($w * $h);







timePrint($time);

/*
class charCode
{
private $a, $b;
function __construct()
	{
	$this->a = array();
	$this->b = array();
	for($i=0;$i<256;++$i)
		{
		$this->a[$i] = chr($i);
		$this->b[chr($i)] = $i;
		}
	}
function chr($code)
	{return $this->b[$code];}
function ord($char)
	{return $this->a[$char];}

}
$charcode = new charCode();
//rename_function('strlen', 'new_strlen');
//override_function('chr', '$code', 'return $charcode->chr($code);');
//override_function('ord', '$char', 'return $charcode->ord($char);');
runkit_function_redefine('chr', '$code', 'return $charcode->chr($code);');
runkit_function_redefine('ord', '$char', 'return $charcode->ord($char);');
*/
?>
peter
PHP › Filtry výběru z DB
18. 12. 2015   #207405

sis, vedle, smazat

peter
PHP › Filtry výběru z DB
18. 12. 2015   #207404

 Tak, muzu dat i zjednodusenou verzi a pro RGB (v komentu pokus pro imagemagic, uprava +-n na +n, upvrava pokus o prepsani funkci chr; ale on chce na prepis funkci a imagemagick instalovat cosi, coz se mi nechce).
1920x1200 rgb, zpracovano za 23s, komprese gzip 40/69 = 58%

<?php
ini_set('max_execution_time', 10000);	//10000s
set_time_limit(10000);   
ini_set('memory_limit', '256M');

function microtime_float()	//pp 17.3.2014
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
$time = array();
$time[] = microtime_float();

function timePrint($time)
{
$time[] = microtime_float();
$t = array();
$t[] = round($time[count($time)-1]-$time[0],3);
for ($i=1;$i<count($time);$i++)
	{
	$t[] = round($time[$i]-$time[$i-1],3);
	}
$t = implode(" | ",$t);
echo '<hr>Cas zpracovani '.$t.' s';
}



function transf(&$img,$w,$h)//&$imagick
{
$out = array('','','');
$c   = array(0,0,0);
$tmp = array(0,0,0);
$tbl = array();
$n = 256;
$nn = $n>>1;
$m = 0;
for ($i=0,$j=-$n;$i<$n;++$i,++$j)
	{

	$tbl[$j] = chr($i);
	$tbl[$i] = chr($i);
/*
	$m = $i<$nn ? $i : $n-1-$i;
	$tbl[$j] = chr($m);
	$tbl[$i] = chr($m);
*/
	}
ksort($tbl);
//$a = 0;
//$iterator = $imagick->getPixelIterator();
$pixel = 0;
for ($j=0;$j<$h;++$j)
	{
	for ($i=0;$i<$w;++$i)
		{
		$pixel = imagecolorat($img, $i, $j);
//return '';
		$c[2] = $pixel & 0xFF;
		$c[1] = ($pixel >> 8) & 0xFF;
		$c[0] = ($pixel >> 16) & 0xFF;
		$out[0] .= $tbl[$c[0]-$tmp[0]];
		$out[1] .= $tbl[$c[1]-$tmp[1]];
		$out[2] .= $tbl[$c[2]-$tmp[2]];
		$tmp[0] = $c[0];
		$tmp[1] = $c[1];
		$tmp[2] = $c[2];
		}
	}
/*
for ($j=0;$j<$h;++$j)
	{
	for ($i=0;$i<$w;++$i)
		{
		$pixel = imagecolorat($img, $i, $j);

foreach($iterator as $row => $pixels)
	{
	foreach ($pixels as $column => $pixel)
		{
var_dump($pixel);
	$iterator->syncIterator();
return '';
*/
return $out[0].$out[1].$out[2];
}

/*
<?php
$imagick = new Imagick("my_image.jpeg");
$iterator = $imagick->getPixelIterator();

foreach($iterator as $row => $pixels) {
    foreach ($pixels as $column => $pixel) {
        // Do something with $pixel
    }
    $iterator->syncIterator();
}
?>
*/



$name1 = "img/jp-bwgirl.jpeg";	//
$name1 = "img/tropical-island-hut.jpg";	//
//$name1 = "img/jp-bwgirl-2.jpeg";	//
$name2 = "tmp/xxx";	//
$bool = file_exists($name1);
echo 'Soubor '.$name1.' '. ($bool ? 'existuje' : 'chyba neexistuje').'<br>';
$b = filesize($name1);

$img = imagecreatefromjpeg($name1);
$w = imagesx($img);
$h = imagesy($img);
//$imagick = new Imagick($name1);
//$w = $imagick->getImageWidth();
//$h = $imagick->getImageHeight();

//var_dump($img);
//imagexbm($img, 'simpletext.xbm');
//header('Content-Type: image/vnd.wap.wbmp');
//imagewbmp($img,$name2);
////header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
////image2wbmp($img);

$b = $w*$h*3;
$out = '';
$out = transf($img,$w,$h);
imagedestroy($img);




$a = 0;
$out = gzcompress($out,9);	

$file2 = fopen($name2, "wb");
fwrite($file2,$out);
fclose($file2);

$a = strlen($out);	unset($out);
echo '<br>out / in =  floor(10000*$a/$b)/100 % gzip';
echo '<br>'.$a. ' / '. $b .' = '.(floor(10000*$a/$b)/100).'% gzip';
echo '<br>'.$w. ' x '. $h .' = '.($w * $h);







timePrint($time);

/*
class charCode
{
private $a, $b;
function __construct()
	{
	$this->a = array();
	$this->b = array();
	for($i=0;$i<256;++$i)
		{
		$this->a[$i] = chr($i);
		$this->b[chr($i)] = $i;
		}
	}
function chr($code)
	{return $this->b[$code];}
function ord($char)
	{return $this->a[$char];}

}
$charcode = new charCode();
//rename_function('strlen', 'new_strlen');
//override_function('chr', '$code', 'return $charcode->chr($code);');
//override_function('ord', '$char', 'return $charcode->ord($char);');
runkit_function_redefine('chr', '$code', 'return $charcode->chr($code);');
runkit_function_redefine('ord', '$char', 'return $charcode->ord($char);');
*/
?>

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý