martinberlin / cale-integrations

CALE configurator to add APIs to your epaper screens - PHP/Symfony 4.4
https://cale.es
MIT License
6 stars 0 forks source link

97/99 Integrate screenshot tool in Symfony #7

Closed martinberlin closed 4 years ago

martinberlin commented 4 years ago

CALE_screenPreview

Still not 100% clear how this will be done but since responding with the image from PHP-Fpm (7.2) is not rendering correctly in ESP32 (And I don't know why) we might keep the screenshot tool in a separate URL using PHP 7.2 as an Apache module.

Basically the main idea to integrate this is to add cache so first request is slow but calls in the next 10 minutes or so (Defined by the user) will be faster. This will make the response a lot faster for the ESP32 device and at the same time prevent not make too many external API requests. I propose the following dropdown for Cache seconds:

And then some screenshot / image control options:

martinberlin commented 4 years ago

Output settings integrated. Still not 100% happy with the fact URLs are too large. CALE-screen-out The fact here is: Pointing it to an internal URL like I wanted, ex. being this the HTML url:

http://cale.fasani.de/fasani/render/5e4c276470e42

To wrap it internally, like: http://cale.fasani.de/fasani/bmp/5e4c276470e42

And doing the screenshot request in Symfony, hiding the final URL, it delivers the image to the browser but in C on the firmware I cannot detect the BMP headers. And I really don't know why. I just understand that PHP as an apache module and as FPM cgi like it runs now on cale.es are two different things and ESP32 likes the first. But more than that I cannot assure. So one of the alternatives to avoid having a long URL such as:

http://bmp.cale.es?u=http%3A%2F%2Fcale.fasani.de%2Ffasani%2Frender%2F5e4c276470e42&w=800&h=480&b=100&d=1&c=0&cache=30

Would be to pass just the screenID and the username: http://img.cale.es/fasani/5e4c276470e42

Hostnames update: I updated bmp.cale.es in favour of img.cale.es so we can deliver different types of image

And do one or two DB queries there to resolve the rest. Having a long URL is not desired. We should offer also the possibility to have both SSH and non SSH alternatives.

martinberlin commented 4 years ago

Pending live deploy

martinberlin commented 4 years ago
    /**
     * @deprecated since we want shorter URLs
     * @param $htmlUrl
     * @param Screen $screen
     * @return string
     */
    private function bmpUrlGetParams($htmlUrl, Screen $screen) {
        $extraParams = [
            'u' => $htmlUrl,
            'w' => $screen->getDisplay()->getWidth(),
            'h' => $screen->getDisplay()->getHeight(),
            'b' => $screen->getOutBrightness(),
            'z' => $screen->getOutZoomFactor(),
            'd' => $screen->getOutBitDepth(),
            'c' => $screen->getOutCompressed(),
            'cache' => $screen->getOutCacheSeconds()
        ];
        $url = $_ENV['SCREENSHOT_TOOL'].'?'.http_build_query($extraParams);
        return $url;
    }

Goes away as planned. Now image dev server is: http://img-dev.cale.es

And using username/screenid will retrieve all this parameters from the DB keeping your URL short. This enables also to update all this paramters in real time, without having them fixed on the ESP32 Url, I think it was a real important update

martinberlin commented 4 years ago

Ready for live.

8 is still pending and it’s an important security protection

martinberlin commented 4 years ago

Is working and did yesterday night some last moment corrections. For reasons I describe here the screenshot tool is the only part of this project that is private on Github.