> ($n - 1); return ($x >> $n) | $mask; } return (int)$x >> (int)$n; } function update_crc($crc, $buf, $len) { global $crc_table_computed, $crc_table; $c = $crc; if (!$crc_table_computed) { make_crc_table(); } for ($n = 0; $n < $len; $n++) { $c = $crc_table[($c ^ ord($buf[$n])) & 0xff] ^ (SHR($c, 8)); } return $c; } function crc($data, $len) { return update_crc(-1, $data, $len) ^ -1; } /** * Debug method only to display on the screen the hexadecimal of a file. */ function hex($bin) { echo ''; $c = strlen($bin); $remember = ''; for($i = 0; $i < $c;) { for($j = 0; $j < 16; $j++, $i++) { if($i < $c) { $o = ord($bin[$i]); $remember .= ($o >= 32 && $o <= 126) ? $bin[$i] : '.'; printf('%02X ', ord($bin[$i])); } else { break 2; } } echo '    '; echo htmlentities($remember); $remember = ''; echo '
'; } echo str_repeat('   ', 16 - ($i % 16)); echo '    '; echo htmlentities($remember); echo '
'; } function createCode($code, $content) { $contentLength = strlen($content); return "\0\0\0" . chr($contentLength) . $code . $content . pack('N', crc($code . $content, $contentLength + 4)); } // PNG: $text = "Copyright\0Generated with Barcode Bakery for PHP http://www.barcodebakery.com"; $encoded = createCode('tEXt', $text); $unpacked = unpack('H*', $encoded); $unpacked = $unpacked[1]; echo '
'; hex($encoded); echo '
'; echo strtoupper($unpacked); echo '
'; echo pack('H*', $unpacked); echo '


'; // JPG: $text = "Generated with Barcode Bakery for PHP http://www.barcodebakery.com"; $length = strlen($text) + 2; $encoded = chr(0xff) . chr(0xfe) . chr($length & 0xff00) . chr($length & 0x00ff) . $text; $unpacked = unpack('H*', $encoded); $unpacked = $unpacked[1]; echo '
'; hex($encoded); echo '
'; echo strtoupper($unpacked); echo '
'; echo pack('H*', $unpacked);