[PHP]代码
<?php /** * @link http://www.php.cn/ * @author Jakub Vrana, http://www.php.cn/ * @copyright 2009 Jakub Vrana * @license http://www.php.cn/ Apache License, Version 2.0 */ /** LZW compression * @param string data to compress * @return string binary data */ function lzw_compress($string) { // compression $dict = array_flip(range("\0", "\xFF")); $dict_size = 256; $word = $string[0]; $dict_count = 256; $bits = 8; $bits_max = 256; $return = ""; $rest = 0; $rest_length = 0; for ($i = 1, $j = strlen($string); $i < $j; $i++) { $x = $string[$i]; $y = $word . $x; if (isset($dict[$y])) { $word .= $x; } else { $rest = ($rest << $bits) + $dict[$word]; $rest_length += $bits; $dict_count++; if ($dict_count > $bits_max) { $bits_max = 1 << ++$bits; } while ($rest_length > 7) { $rest_length -= 8; $return .= chr($rest >> $rest_length); $rest &= (1 << $rest_length) - 1; } $dict[$y] = $dict_size++; $word = $x; } } $rest = ($rest << $bits) + $dict[$word]; $rest_length += $bits; $dict_count++; if ($dict_count > $bits_max) { $bits_max = 1 << ++$bits; } while ($rest_length > 0) { if($rest_length>7){ $rest_length -= 8; $return .= chr($rest >> $rest_length); $rest &= (1 << $rest_length) - 1; }else{ $return .= chr($rest << (8 - $rest_length)); $rest_length = 0; } } return $return; } /** LZW decompression * @param string compressed binary data * @return string original data */ function lzw_decompress($binary) { // convert binary string to codes $rest = 0; $rest_length = 0; $out_count = 257; $bits = 9; $bits_max = 512; // decompression $dict = range("\0", "\xFF"); $w = $binary[0]; $return = $w; for ($i = 1, $j = strlen($binary); $i < $j; $i++) { $rest = ($rest << 8) + ord($binary[$i]); $rest_length += 8; if ($rest_length >= $bits) { $rest_length -= $bits; // decompression $e = $dict[$rest >> $rest_length]; if (!isset($e)) { $e = $w . $w[0]; } $return .= $e; $dict[] = $w . $e[0]; $w = $e; //--decompression $rest &= (1 << $rest_length) - 1; if (++$out_count > $bits_max) { $bits_max = 1 << ++$bits; } } } return $return; } ?>
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
3 週前ByDDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
2 週前ByDDD
在哪裡可以找到原子中的起重機控制鑰匙卡
3 週前ByDDD
<🎜>:死鐵路 - 如何完成所有挑戰
4 週前ByDDD
Atomfall指南:項目位置,任務指南和技巧
1 個月前ByDDD

熱工具

SublimeText3漢化版
中文版,非常好用

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),