Example #1
0
function barcode($image, $step = 1, $length = false)
{
    if (function_exists('imagefilter') && function_exists('imagetruecolortopalette') && function_exists('imagecolorset') && function_exists('imagecolorclosest')) {
        //Gaussian blur to fill in holes from dithering
        imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
        //force two colors; dithering = FALSE
        imagetruecolortopalette($image, FALSE, 2);
        //find the closest color to black and replace it with actual black
        imagecolorset($image, imagecolorclosest($image, 0, 0, 0), 0, 0, 0);
        //find the closest color to white and replace it with actual white
        imagecolorset($image, imagecolorclosest($image, 255, 255, 255), 255, 255, 255);
    }
    //search
    $height = imagesy($image);
    for ($i = $step; $i < $height - $step; $i += $step) {
        $a = barWidth($image, $i);
        $w = nwWidth($a);
        if ($w['n'] != 0 && $w['w'] != 0) {
            $s = widthsToNW($a, $w['n'], $w['w']);
            if (validate($s)) {
                $code = NWtoCode($s);
                if ($code != "false" && (!$length || strlen($code) == $length)) {
                    return $code;
                }
            } else {
                if (validateCodaBar($s)) {
                    $code = NWtoCodeCodaBar($s . "N");
                    //remember to add the last space
                    if ($code != "false") {
                        $code = substr($code, 1, -1);
                        //remove the start and stop characters
                        if (!$length || strlen($code) == $length) {
                            return $code;
                        }
                    }
                }
            }
        }
    }
    return false;
}
    			<?php 
    $bar_width = "273px";
    $bar_height = "20px";
    $ally_img = "wow/static/images/services/status/ally.png";
    $horde_img = "wow/static/images/services/status/horde.png";
    //Show percent online (true = yes, false = no)
    $show_percent = true;
    $alliance = array("1", "3", "4", "7", "11", "22");
    $horde = array("2", "5", "6", "8", "9", "10");
    $p = @getPlayers($server_cdb);
    $a = @doFaction($server_cdb, $alliance);
    $h = @doFaction($server_cdb, $horde);
    $ap = @percent($a, $p);
    $hp = @percent($h, $p);
    $b = @barWidth($a, $p, 273);
    $c = @barWidth($h, $p, 273);
    echo "<a data-tooltip='" . doFaction($server_cdb, $alliance) . " <font style=\"color:#3399ff;font-weight:bold;\">" . $Status['Ali'] . "</font> <small>" . $Status['PlOnLine'] . "</small>'\\><div style=\"width:" . $bar_width . ";height:" . $bar_height . ";\">\n    \t\t\t<div style=\"float:left;text-align:right;background:url(./" . $ally_img . ");width:" . $b . "px;height:20px;\">";
    if ($show_percent) {
        echo "<font style=\"color:#FFFFFF;font-weight:bold;\"><center>{$ap}%</center></font></a>";
    }
    echo "<a data-tooltip='" . doFaction($server_cdb, $horde) . " <font style=\"color:#ff3333;font-weight:bold;\">" . $Status['Horde'] . "</font> <small>" . $Status['PlOnLine'] . "</small>'\\></div>\n    \t\t\t<div style=\"float:right;text-align:left;background:url(./" . $horde_img . ");background-position:right;width:" . $c . "px;height:20px;\">";
    if ($show_percent) {
        echo "<font style=\"color:#FFFFFF;font-weight:bold;\"><center>{$hp}%</center></font></a>";
    }
    echo "</div>\n    \t\t\t</div>";
    ?>
    		</center>
    		</div>
    	</div>
    </div>
	<br />
Example #3
0
function barcode($image, $step = 1, $length = false, $numsonly = false)
{
    if (function_exists('imagefilter') && function_exists('imagetruecolortopalette') && function_exists('imagecolorset') && function_exists('imagecolorclosest')) {
        //Gaussian blur to fill in holes from dithering
        imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
        //force two colors; dithering = FALSE
        imagetruecolortopalette($image, FALSE, 2);
        //find the closest color to black and replace it with actual black
        imagecolorset($image, imagecolorclosest($image, 0, 0, 0), 0, 0, 0);
        //find the closest color to white and replace it with actual white
        imagecolorset($image, imagecolorclosest($image, 255, 255, 255), 255, 255, 255);
    }
    //search
    $height = imagesy($image);
    for ($i = $step; $i < $height - $step; $i += $step) {
        $a = barWidth($image, $i);
        $w = nwWidth($a);
        if ($w['n'] != 0 && $w['w'] != 0) {
            $s = widthsToNW($a, $w['n'], $w['w']);
            if (validate($s)) {
                $code = NWtoCode($s);
                if ($code != "false" && (!$length || strlen($code) == $length)) {
                    return $code;
                }
            } else {
                if (validateCodaBar($s)) {
                    $code = NWtoCodeCodaBar($s . "N");
                    //remember to add the last space
                    if ($code != "false") {
                        $code = substr($code, 1, -1);
                        //remove the start and stop characters
                        if (!$length || strlen($code) == $length) {
                            return $code;
                        }
                    }
                }
            }
        }
    }
    if (OCR_ENABLED) {
        //use tesseract to find the "barcode" or any text as OCR
        $tmp = tempnam(TEMPORARY_DIRECTORY, "BARCODE");
        imagepng($image, $tmp);
        exec(TESSERACT_BIN . " {$tmp} {$tmp} -psm 3");
        //run tessearct in single line mode
        $result = file_get_contents($tmp . ".txt");
        unlink($tmp);
        unlink($tmp . ".txt");
        if (!empty($result)) {
            //check length if set to check
            //
            //
            if ($length && !$numsonly) {
                $res = preg_match("/([0-9]{" . $length . "})/", $result, $matches);
                if ($res) {
                    return $matches[0];
                }
            }
            $nums = preg_replace('/\\D+/', '', $result);
            // numbers only
            if ($length && strlen($nums) == $length) {
                return $nums;
            } else {
                if (!$length && !$numsonly) {
                    return $result;
                } else {
                    if (!$length && $numsonly) {
                        return $nums;
                    }
                }
            }
            //if no length is set just return what is read by OCR
        }
    }
    return false;
}