[PYTHON] I want to take a screenshot of the site on Docker using any font

Purpose: I want to take a screenshot of the site using any font on Docker, plus I want to test

There is an article until I take a screenshot, but I couldn't find an article in Japanese that I did until I set an arbitrary font, so I wrote it.

All sources are here https://github.com/frkwy/xvfb_screenshot_on_docker

The fonts and sentences used this time are [High school girl style? Download the cute extra-fine font "JK Gothic L" | Font and Cute font [http://font.cutegirl.jp/jk-font-light.html) Aozora Bunko Natsume Soseki I am a cat I used.

Check fonts and check priorities

The solution is to raise the priority of the font you want to use. fc-list: Font list If it is not here, the font is not installed. This time it's Firefox It's OK if the font you want to use when you execute fc-match -s sarif is at the top. For that, we will create font.conf.

Dockerfile

FROM alpine:latest

COPY fonts.conf /root/.config/fontconfig/
# Please override your favorite font file path
COPY JKG-L_3.ttf /root/.local/share/fonts/

RUN apk update && apk add python3 xvfb firefox dbus && rm -rf /var/cache/apk/*
RUN python3 -m ensurepip
RUN pip3 install --upgrade pip selenium xvfbwrapper

RUN fc-cache -fv

CMD ["python3", "/host/example.py"]

font.conf Assuming that the font is already installed in the above Dockerfile, Bring the priority of the font you want to use to the top with binding =" strong ".

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
   <match target="pattern">
        <edit name="family" mode="assign" binding="strong">
           <string>JK Gothic L</string>
        </edit>
    </match>
</fontconfig>

This is a screenshot actually taken. Screenshot_from_2016-03-21 20:30:14.png

Recommended Posts

I want to take a screenshot of the site on Docker using any font
Keras I want to get the output of any layer !!
I want to sort a list in the order of other lists
Python: I want to measure the processing time of a function neatly
I don't want to take a coding test
I want to customize the appearance of zabbix
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to set a life cycle in the task definition of ECS
I want to add silence to the beginning of a wav file for 1 second
I want to see a list of WebDAV files in the Requests module
I made a script to record the active window using win32gui of Python
100 image processing knocks !! (021-030) I want to take a break ...
I want to grep the execution result of strace
Take a screenshot of the LCD with Python-LEGO Mindstorms
I want to find a popular package on PyPi
I want to fully understand the basics of Bokeh
I want to install a package of Php Redis
I want to automate ssh using the expect command!
I want to increase the security of ssh connections
[Python3] Take a screenshot of a web page on the server and crop it further
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
[Python] I made a system to introduce "recipes I really want" from the recipe site!
The story of Linux that I want to teach myself half a year ago
I want to plot the location information of GTFS Realtime on Jupyter! (With balloon)
I want to collect a lot of images, so I tried using "google image download"
I want to automate ssh using the expect command! part2
I want to start a lot of processes from python
I want to use only the normalization process of SudachiPy
NikuGan ~ I want to see a lot of delicious meat! !!
I want to get the operation information of yahoo route
I made a function to check the model of DCGAN
I want to judge the authenticity of the elements of numpy array
I made a VGG16 model using TensorFlow (on the way)
I want to know the features of Python and pip
I want to know the legend of the IT technology world
I want to create a Dockerfile for the time being.
I tried to compare the accuracy of machine learning models using kaggle as a theme.
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I want to find the intersection of a Bezier curve and a straight line (Bezier Clipping method)
I want to output a beautifully customized heat map of the correlation matrix. matplotlib edition
How to easily draw the structure of a neural network on Google Colaboratory using "convnet-drawer"
I want to make a voice changer using Python and SPTK with reference to a famous site
I tried to automate the construction of a hands-on environment using IBM Cloud's SoftLayer API
How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)
I want to get the name of the function / method being executed
I want to record the execution time and keep a log.
I tried to make a site that makes it easy to see the update information of Azure
I tried to get the index of the list using the enumerate function
I will publish a shell script created to reduce the trouble of creating LiveUSB on Linux
[Python] I wrote the route of the typhoon on the map using folium
I tried to make a regular expression of "amount" using Python
I want to read the html version of "OpenCV-Python Tutorials" OpenCV 3.1 version
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I want to output the beginning of the next month with Python
I want to automatically operate Chrome on Windows from a virtual machine (ubuntu) started using Vagrant
I wanted to challenge the classification of CIFAR-10 using Chainer's trainer
I tried to make a regular expression of "date" using Python
I tried to digitize the stamp stamped on paper using OpenCV
I want to create a system to prevent forgetting to tighten the key 1
I tried to get a list of AMI Names using Boto3
I tried to register a station on the IoT platform "Rimotte"