note 41370 deleted from function.imagecreatefromjpeg by cmb
| From: | cmb@php.net | Date: | Sun, 11 Dec 2016 11:17:07 +0000 |
| Subject: | note 41370 deleted from function.imagecreatefromjpeg by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208507@lists.php.net to get a copy of this message | ||
Note Submitter: Sne
----
small script that calculates square (in %) of eche color on the PNG image.
<?
$t1=time();
$im1=ImageCreatefrompng('1.png'); //name of the png file
echo "<img src=1.png>";
$widthIm=ImageSX($im1);
$heightIm=ImageSY($im1);
$total=$widthIm*$heightIm;
$cvcol=imagecolorstotal($im1);
for ($i=0; $i<$widthIm; $i++){
for ($j=0; $j<$heightIm; $j++){
$tochka=imagecolorat($im1,$i,$j);
$num[$tochka]=$num[$tochka]+1;
}
}
echo "<br><br>$widthIm x $heightIm ($total pixels).";
echo " Number of colors in pallette - $cvcol<br><br>
";
echo "<table width=400 border =1>";
for ($k=0; $k<$cvcol; $k++) {
$proc=round($num[$k]/$total*100, 2);
$Palitra =ImageColorsForIndex($im1,$k);
$Palitra[red]= dechex($Palitra[red]);
$Palitra[green]= dechex($Palitra[green]);
$Palitra[blue]= dechex($Palitra[blue]);
echo "<tr><td>$k</td><td
width=100>$Palitra[red]-$Palitra[green]-$Palitra[blue]</td>";
echo "<td width=100>$proc %</td>";
echo "<td width=100 bgcolor=$Palitra[red],$Palitra";
echo "[green],$Palitra[blue]> </td></tr>";
}
echo "</table>";
imagedestroy($im1);
$t2=-$t1+time();
echo "<br>Time past: $t2 sec";
?>