mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
fix api ip-adapter
This commit is contained in:
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import base64
|
||||
from PIL import Image
|
||||
from rich import print # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
def encode(file: str):
|
||||
image = Image.open(file) if os.path.exists(file) else None
|
||||
print(f'Input: file={file} image={image}')
|
||||
if image is None:
|
||||
return None
|
||||
if image.mode != 'RGB':
|
||||
image = image.convert('RGB')
|
||||
with io.BytesIO() as stream:
|
||||
image.save(stream, 'JPEG')
|
||||
image.close()
|
||||
values = stream.getvalue()
|
||||
encoded = base64.b64encode(values).decode()
|
||||
return encoded
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.argv.pop(0)
|
||||
fn = sys.argv[0] if len(sys.argv) > 0 else ''
|
||||
b64 = encode(fn)
|
||||
print('=== BEGIN ===')
|
||||
print(f'{b64}')
|
||||
print('=== END ===')
|
||||
|
||||
Reference in New Issue
Block a user