Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM php:7.3-apache
RUN echo "deb http://http.debian.net/debian/ buster main contrib non-free" > /etc/apt/sources.list && \
echo "deb http://http.debian.net/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/ buster/updates main contrib non-free" >> /etc/apt/sources.list && \
apt-get update
RUN apt-get install -y --no-install-recommends \
imagemagick \
ghostscript \
libmagickwand-dev \
librsvg2-bin \
xfonts-100dpi \
xfonts-75dpi \
xfonts-base \
fonts-roboto \
fonts-inconsolata \
ttf-mscorefonts-installer \
fonts-open-sans \
fontconfig
COPY server/fontconfig/* /etc/fonts/conf.d/
RUN fc-cache -f -v
RUN printf "\n" | pecl install imagick
RUN mkdir -p /tmp
RUN chmod a+rw /tmp

RUN docker-php-ext-enable imagick
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ To reuse the display driver for another board, just redefine the macros to point

The server should be copied to a PHP enabled server, create a config.php and fill it. Also create a screens/ dir and chmod it to be world readable/writtable.

How to run with docker
----------------------

If you have docker-compose installed, you can do a simple
```
docker-compose up --build
````
to start the server. To run it with docker directly you can run
```
docker build -t php-im/wifi-display .
docker run -p 80:80 -v "$PWD/server":/var/www/html php-im/wifi-display
```

Schematics
----------

Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: "3"
networks:
web:
driver: "bridge"
services:
wifi-display:
build:
context: .
dockerfile: Dockerfile
volumes:
- "./server:/var/www/html"
ports:
- "80:80"
networks:
- "web"
2 changes: 1 addition & 1 deletion server/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<![endif]-->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="//code.interactjs.io/v1.2.6/interact.min.js"></script>
<script src="//cdn.jsdelivr.net/interact.js/1.2.6/interact.min.js"></script>

<script type="text/javascript">

Expand Down
38 changes: 38 additions & 0 deletions server/fontconfig/99-antialiasing-off.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How's this file loaded and used?

Copy link
Author

@squix78 squix78 Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me quite a while to get it to run. This file is copied into the docker container. The command
RUN fc-cache -f -v`
in Dockerfile then processes it. All linux processes working with fonts then use these hints to do the font rendering, including PHP/Imagemagick.

Here is some more information about fc-cache/fontconfig: https://linux.die.net/man/1/fc-cache

And the result of the file is that the fonts are rendered without antialiasing which results in more crisp text. In a display with gray scales antialiasing is great but on a pure black & white display it is distorting the text

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so it's a docker specific thing. Gotcha!

<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

<match target="pattern" >
<!-- autohint was the old automatic hinter when hinting was patent
protected, so turn it off to ensure any hinting information in the font
itself is used, this is the default -->
<edit mode="assign" name="autohint"> <bool>false</bool></edit>

<!-- hinting is enabled by default -->
<edit mode="assign" name="hinting"> <bool>false</bool></edit>

<!-- for the lcdfilter see http://www.spasche.net/files/lcdfiltering/ -->
<edit mode="assign" name="lcdfilter"> <const>lcdnone</const></edit>

<!-- options for hintstyle:
hintfull: is supposed to give a crisp font that aligns well to the
character-cell grid but at the cost of its proper shape.
hintmedium: poorly documented, maybe a synonym for hintfull.
hintslight is the default: - supposed to be more fuzzy but retains shape.
hintnone: seems to turn hinting off.
The variations are marginal and results vary with different fonts -->
<edit mode="assign" name="hintstyle"> <const>hintnone</const></edit>

<!-- antialiasing is on by default and really helps for faint characters
and also for 'xft:' fonts used in rxvt-unicode -->
<edit mode="assign" name="antialias"> <bool>false</bool></edit>

<!-- subpixels are usually rgb, see
http://www.lagom.nl/lcd-test/subpixel.php -->
<edit mode="assign" name="rgba"> <const>rgb</const></edit>

<!-- thanks to the Arch wiki for the lcd and subpixel links -->
</match>

</fontconfig>
3 changes: 1 addition & 2 deletions server/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ static function getRender($widget_name, $settings, $ws, $hs) {
// Image rendering stuff

function renderSVG($id) {
header('Content-type: image/svg+xml');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the content type? I guess it might still work but I also don't see the reason for it. Is this wrong in any way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I actually planned to investigate a bit more why this causes a problem. My current assumption is: rendering the bitmap formats also calls this function. Setting the header here writes the header 'Content-type: image/svg+xml' into the png/proprietary bitmap output stream. If I don't remove this line the bitmap is not displayed on the home screen of the admin page. Probably the header(..) call should be moved to the place where svg, png and proprietary bitmap are processed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errr good catch! Yeah this should indeed be moved in that case.
However I do not agree with the statement that header() writes to the bytestream. In PHP, if you already sent the headers, any header() results in an error (headers already sent).
I'm hesitant to merge this line change :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is exactly the reason, why I had to remove the line. If the line is present the preview image cannot be rendered, because of the error you mentioned

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, makes sense. I guess my php.ini doesnt enable warnings on the page (you can disable that to the php error log where it belongs). Not nice that users can see whats going on :P
Can we at least move this line to the correct place?


// Read the screen and parse it as JSON
$scr = file_get_contents("screens/".$id);
Expand Down Expand Up @@ -108,7 +107,7 @@ function renderBMP($id, $numc, $maxwidth, $maxheight) {
$im->transformImageColorspace(imagick::COLORSPACE_GRAY);
$im->posterizeImage($numc, imagick::DITHERMETHOD_NO);
$im->setImageBackgroundColor('white');
$im = $im->flattenImages();
$im = $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
unlink($svgf);
unlink($svgf.".png");
return $im;
Expand Down