示例#1
0
 def save(self) -> bytes:
     if self._messageStorage:
         self.update(self._messageStorage, force=True)
     wordcloud = self._wordcloud.generate_from_frequencies(
         self._wordFreqency)
     with tmpFile(ext=".png") as tmpFileName:
         wordcloud.to_file(tmpFileName)
         with open(tmpFileName, "rb") as f:
             fileRead = f.read()
     return convertImageFormat(fileRead)
示例#2
0
def mosaicImage(img: bytes) -> bytes:
    with tmpFile() as tf:
        with open(tf, "wb") as f:
            f.write(img)
        with Image.open(tf) as im:
            blured = im.filter(ImageFilter.GaussianBlur(radius=10))
            blured.save(tf, "PNG")
        with open(tf, "rb") as f:
            fileRead = f.read()
    imageWithText = textAlign(fileRead, "R-18")
    return convertImageFormat(imageWithText)
示例#3
0
def downloadImage(url: str, mosaic: Optional[bool] = False) -> str:
    headers = {"Referer": "https://www.pixiv.net"}
    r = requests.get(url,
                     headers=headers,
                     timeout=(6, 12),
                     proxies=NetworkUtils.proxy)
    r.raise_for_status()
    if mosaic:
        pngImage = mosaicImage(r.content)
    else:
        pngImage = convertImageFormat(r.content)
    return f"base64://{b64encode(pngImage).decode()}"
示例#4
0
 def getImage(imgLink: str):
     dataGet = requests.get(urljoin("https://cn.bing.com/", imgLink),
                            timeout=(6, None))
     dataGet.raise_for_status()
     return convertImageFormat(resizeImage(dataGet.content, height=720))
示例#5
0
def downloadImage(url: str) -> str:
    r = requests.get(url, proxies=NetworkUtils.proxy, timeout=(3, 21))
    r.raise_for_status()
    resp = b64encode(convertImageFormat(r.content)).decode()
    return f"base64://{resp}"