/ crates / teleghosts / import_inline_img.py
import_inline_img.py
 1  #!/usr/bin/python3
 2  
 3  from base64 import b64encode as b64e
 4  from pathlib import Path
 5  import sys
 6  
 7  
 8  fin = Path(sys.argv[1])
 9  
10  if fin.stat().st_size > 9500:
11      print("The file is too large")
12      sys.exit(1)
13  
14  if not (fin.suffix == ".jpg" or fin.suffix == ".jpeg"):
15      print(f"Invalid file extension: '{ext}'")
16      sys.exit(1)
17  
18  fout = f"./res/{fin.stem}.img"
19  
20  i = open(fin, "rb")
21  contents = i.read()
22  
23  o = open(fout, "wb")
24  o.write(b"data:image/jpg;base64,")
25  o.write(b64e(contents))
26  
27  print(f"[+] imported to '{fout}'")