Skip to content

Commit

Permalink
增加一些必要的说明文档
Browse files Browse the repository at this point in the history
  • Loading branch information
viyiviyi committed Oct 8, 2023
1 parent 875eb15 commit cb9c159
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 0 additions & 2 deletions preload.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def dencrypt_image(image,psw):
# pixels[x, y] = (r,g,b) if len(pix) == 3 else (r,g,b,pix[3])

class EncryptedImage(Image.Image):

password = ''

def save(self, filename,*args, **kwargs):
# 加密图片数据
if EncryptedImage.password:
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# stable-diffusion-webui 图片加密插件

**这个插件会导致jpg和webp图片质量降低,估计是加密后再保存,和这两个格式的图片压缩算法有关。**

- 这个插件会修改Image对象,重写了save方法,启用将会导致所有的图片保存行为都被加密
- 这个插件会导致图片浏览器不能正确显示缩略图,因为缩略图是在加密后的图像上产生的
- 这个插件会导致读取未加密的图片时出现错误,因为没有给图片做标记是否加密
Expand All @@ -10,4 +12,10 @@
## 启用方式

1. 安装到插件目录
2. 在启动参数增加 ```--encrypt-pass=你的密码```
2. 在启动参数增加 ```--encrypt-pass=你的密码```

## 批量解密脚本使用方式

1. 将utils文件夹内的 dencrypt_image_all.py 文件放到包含加密图片的文件夹(尽量文件夹内只有已加密的图片,否则正常文件解密后会得到乱码的文件,不会影响原文件)
2. 如果有Python环境,在图片文件夹打开命令行 执行 ```python dencrypt_image_all.py``` (dencrypt_image_all.py 只是示例名,实际名称看你复制的脚本文件)
3. 如果没有Python环境,需要安装Python环境后再执行步骤2
5 changes: 4 additions & 1 deletion scripts/encrypt_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
password = getattr(shared.cmd_opts, 'encrypt_pass', None)

if password:
print('图片加密已经启动 加密方式 1')
EncryptedImage.password = password
section = ("encrypt_image",'图片加密' if shared.opts.localization == 'zh_CN' else "encrypt image" )
shared.opts.add_option(
Expand All @@ -15,4 +16,6 @@
section=section,
),
)
shared.opts.data['encrypt_pass_hash'] = get_sha256(password)
shared.opts.data['encrypt_pass_hash'] = get_sha256(password)
else:
print('图片加密插件已安装,但缺少密码参数未启动')
2 changes: 1 addition & 1 deletion utils/dencrypt_all_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main():
skipped_files = [] # 存储已跳过的文件名

for filename in os.listdir('.'):
if filename.endswith('.jpg') or filename.endswith('.png'): # 只处理jpg和png格式的图片文件
if filename.endswith('.jpg') or filename.endswith('.png') or filename.endswith('.webp') or filename.endswith('.jpeg'):
output_filename = os.path.join(output_dir, filename)
if os.path.exists(output_filename):
skipped_files.append(filename)
Expand Down

0 comments on commit cb9c159

Please sign in to comment.