yvbbrjdr / i3lock-fancy-rapid

A faster implementation of i3lock-fancy.
BSD 3-Clause "New" or "Revised" License
149 stars 20 forks source link

No composite images #1

Open TheKarlo95 opened 6 years ago

TheKarlo95 commented 6 years ago

There is no feature for adding images to compose with the screenshot. Also lacks other features from original i3lock-fancy.

yvbbrjdr commented 6 years ago

Yes. This project has just been launched so there might be lack of features. I'm considering adding these features. Now just consider it a proof of concept of fast blur and PNG encoding. I'll elaborate other things soon.

Alveel commented 5 years ago

I like it so far, significantly faster than using mogrify -blur.

Good work :+1:

madnight commented 5 years ago

Well you don't need C in this case because there are very fast python image processing librarys (with C extensions).

import subprocess
import os
import mss
import sys

from PIL import Image
from screeninfo import get_monitors

monitors = get_monitors()

with mss.mss() as sct:

    root_w = sum(map(lambda x: x.width, monitors))
    root_h = max(map(lambda x: x.height, monitors))

    # take screenshot
    monitor = {"top": 0, "left": 0, "width": root_w, "height": root_h}
    sct_img = sct.grab(monitor)
    img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")

    # pixelate
    imgSmall = img.resize(
        (int(img.size[0] / 10), int(img.size[1] / 10)), resample=Image.BILINEAR
    )
    result = imgSmall.resize(img.size, Image.NEAREST)

    icon = Image.open(sys.argv[1])

    # calc lock icon position on primary display
    primary = monitors[0]
    area = (
        int(((primary.width / 2) + primary.x) - icon.size[0] / 2),
        int(((primary.height / 2) + primary.y) - icon.size[1] / 2),
    )

    # add lock icon to bg image
    result.paste(icon, area, icon)

    subprocess.run(
        [
            "i3lock",
            "--raw",
            str(result.width) + "x" + str(result.height) + ":rgb",
            "-i",
            "/dev/stdin",
        ],
        stdout=subprocess.PIPE,
        input=result.tobytes(),
    )

python lock.py "$HOME/lock.png"

This scripts executes in 0.238 sec on my T480s notebook with 3 external monitors. (prior to the i3lock call)