1 个不稳定版本
0.1.0 | 2021年6月1日 |
---|
#57 in #encoded
在 seagul 中使用
450KB
634 行
一个将任意数据编码到图像的库,这种技术也称为隐写术。
这是seagul
命令行应用程序的基础。
基本示例
编码
读取一张图片,并使用编码的某些诗句重新保存,使用每个像素蓝色通道的最后2位来编码它们
let encode_result = super::ImageEncoder::from("source.png")
.set_use_n_lsb(2)
.set_use_channel(RgbChannel::Blue)
.encode_data(
b"
Midway upon the journey of our life
I found myself within a forest dark,
For the straightforward pathway had been lost.
Ah me! how hard a thing it is to say
What was this forest savage, rough, and stern,
Which in the very thought renews the fear.
So bitter is it, death is little more;
But of the good to treat, which there I found,
Speak will I of the other things I saw there.
I cannot well repeat how there I entered,
So full was I of slumber at the moment
In which I had abandoned the true way.",
);
assert!(encode_result.is_ok(), "Encoding failed");
encode_result
.unwrap()
.save("encoded.png", ImageFormat::Png)
.expect("Could not create output file");
解码
let decoded = ImageDecoder::from("encoded.png")
.set_use_n_lsb(2)
.set_use_channel(RgbChannel::Blue)
.until_marker(Some(b"way.")) // <- If you know how the message ends
.decode();
assert!(decoded.is_ok());
let decoded = decoded.unwrap().as_raw();
println!("Raw decoded:\n{}", decoded_string);
支持的格式
尽管几乎每个主要的图像格式都支持作为输入,但目前仅支持PNG和BMP作为输出格式。JPEG和其他格式的支持正在计划中。
依赖关系
~14MB
~81K SLoC