MCPcopy Create free account
hub / github.com/MearaY/StegaPy / data_hiding_ui

Function data_hiding_ui

app.py:125–314  ·  view source on GitHub ↗

数据隐藏界面

(plugin_name, use_compression, use_encryption,
                  password, encryption_algorithm, max_bits)

Source from the content-addressed store, hash-verified

123
124
125def data_hiding_ui(plugin_name, use_compression, use_encryption,
126 password, encryption_algorithm, max_bits):
127 """数据隐藏界面"""
128 st.header("📦 数据隐藏")
129
130 tab1, tab2 = st.tabs(["嵌入数据", "提取数据"])
131
132 with tab1:
133 st.subheader("将数据嵌入到图像中")
134
135 col1, col2 = st.columns(2)
136
137 with col1:
138 st.write("**封面图像**")
139 cover_file = st.file_uploader(
140 "上传封面图像",
141 type=['png', 'jpg', 'jpeg', 'bmp'],
142 help="用于隐藏数据的封面图像"
143 )
144
145 if cover_file:
146 # 重置文件指针并读取数据用于预览
147 cover_file.seek(0)
148 cover_image = Image.open(cover_file)
149 st.image(cover_image, caption="封面图像", width='stretch')
150 # 重置文件指针,确保后续读取时数据可用
151 cover_file.seek(0)
152
153 with col2:
154 st.write("**消息文件**")
155 msg_file = st.file_uploader(
156 "上传要隐藏的消息文件",
157 type=None,
158 help="要隐藏在图像中的文件"
159 )
160
161 if msg_file:
162 st.info(f"文件: {msg_file.name}\n大小: {len(msg_file.read())} 字节")
163 msg_file.seek(0) # 重置文件指针
164
165 if st.button("嵌入数据", type="primary"):
166 if not cover_file:
167 st.error("请上传封面图像")
168 elif not msg_file:
169 st.error("请上传消息文件")
170 else:
171 try:
172 with st.spinner("正在嵌入数据..."):
173 # 获取插件
174 plugin = PluginManager.get_plugin_by_name(plugin_name)
175 if plugin_name in ["LSB", "RandomLSB"]:
176 from StegaPy.plugin.lsb.lsb_config import LSBConfig
177 config = LSBConfig(
178 max_bits_used_per_channel=max_bits,
179 use_compression=use_compression,
180 use_encryption=use_encryption,
181 password=password,
182 encryption_algorithm=encryption_algorithm

Callers 1

mainFunction · 0.85

Calls 9

embed_dataMethod · 0.95
get_diffMethod · 0.95
extract_dataMethod · 0.95
LSBConfigClass · 0.90
StegaPyConfigClass · 0.90
StegaPyClass · 0.85
get_plugin_by_nameMethod · 0.80
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected