├── .gitignore
├── Dockerfile
├── Dockerfile.test
├── LICENSE
├── README.md
├── docker-compose.test.yml
├── docker-compose.yml
├── openapi.yaml
├── requirements.test.txt
├── requirements.txt
├── server.py
├── test_assets
├── jpeg_default.jpeg
├── jpeg_quality_1.jpeg
├── jpeg_quality_100.jpeg
├── pdf_crop.pdf
├── pdf_default.pdf
├── png_border_100.png
├── png_default.png
├── png_embed.png
├── png_height_10.png
├── png_height_1000.png
├── png_scale_5.png
├── png_scale_point5.png
├── png_transparent.png
├── png_width_10.png
├── png_width_1000.png
├── png_width_400_height_200.png
├── svg_default.svg
└── test_input.drawio
└── test_server.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM fedora:latest
2 | WORKDIR /code
3 | RUN dnf install -y python3-pip xorg-x11-server-Xvfb alsa-lib make findutils gdouros-symbola-fonts google-noto-emoji-fonts google-noto-emoji-color-fonts \
4 | && dnf group install -y fonts \
5 | && dnf install -y https://github.com/jgraph/drawio-desktop/releases/download/v19.0.3/drawio-x86_64-19.0.3.rpm \
6 | && dnf clean all \
7 | && rm -rf /var/cache/dnf
8 | COPY requirements.txt server.py openapi.yaml ./
9 | RUN pip3 install -r requirements.txt
10 | ENV HOME /tmp
11 | EXPOSE 5000
12 | ENV FLASK_APP server.py
13 | ENV FLASK_RUN_HOST 0.0.0.0
14 | CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--access-logfile", "-", "server:app"]
--------------------------------------------------------------------------------
/Dockerfile.test:
--------------------------------------------------------------------------------
1 | FROM python:3.8-slim-buster
2 | WORKDIR /code
3 | COPY requirements.test.txt requirements.test.txt
4 | RUN pip install -r requirements.test.txt
5 | COPY test_server.py test_server.py
6 | COPY test_assets test_assets
7 | CMD ["python", "-u", "-m", "pytest", "test_server.py"]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # docker-drawio-renderer
2 | Dockerized service exposing a REST interface for rendering draw.io diagrams into images.
3 |
4 | ## What it does
5 |
6 | [Diagrams.net](https://diagrams.net) has added [command-line options](https://j2r2b.github.io/2019/08/06/drawio-cli.html) to [Draw.io Desktop](https://github.com/jgraph/drawio-desktop) which allow you to automate converting diagrams into images. This is great!
7 |
8 | Unfortunately, Draw.io Desktop is an Electron-based application, and cannot execute without first installing a huge number of dependencies, including a GUI environment such as X11 within which it can run. This makes it difficult to integrate into other services such as Jenkins build pipelines.
9 |
10 | This package puts Draw.io Desktop into a Docker container along with all of its dependencies and a simple HTTP REST server, allowing you to easily call it from other services regardless of platform or language.
11 |
12 | Due to the large number of dependencies, the container produced is very big; I welcome contributions to trim its size down! In the meantime, at least all of this bloat is hidden inside this one container and won't affect the rest of your services.
13 |
14 | ## Running
15 |
16 | ```
17 | docker run -d -p 5000:5000 --shm-size=1g tomkludy/drawio-renderer:latest
18 | ```
19 |
20 | Note the `--shm-size` parameter; this determines the maximum memory that can be used during diagram rendering. If omitted, the default is 256mb. If you hit out-of-memory errors (HTTP status code 413), try increasing the value of this parameter.
21 |
22 | ## API
23 |
24 | New in v1.1: Now it is simpler to use the service from the command-line using `curl`, `wget`, `Invoke-WebRequest` or similar. Specify the `Accept:` request header to the desired output type and send the draw.io file as request content to the `/convert_file` endpoint; for example:
25 |
26 | ```text
27 | curl -d @inputfile.drawio -H "Accept: application/pdf" http://localhost:5000/convert_file?crop=true --output outputfile.pdf
28 | ```
29 |
30 | Supported `Accept:` values:
31 |
32 | | MIME type | Image format |
33 | | - | - |
34 | | `image/png` | PNG |
35 | | `image/jpeg` | JPEG |
36 | | `application/pdf` | PDF |
37 | | `image/svg+xml; encoding=utf-8` | SVG |
38 |
39 | Supported query parameters:
40 |
41 | | Parameter | Description |
42 | | - | - |
43 | | `quality={n}` | Output image quality for JPEG (1-100, default: 90) |
44 | | `transparent=true` | Use transparent background for PNG |
45 | | `embed=true` | Includes a copy of the diagram (for PNG format only) |
46 | | `border={n}` | Sets the border width around the diagram (0-10000, default: 0) |
47 | | `scale={n.m}` | Scales the diagram size (0.0-5.0, 1.0 is default size |
48 | | `width={n}` | Fits the generated image/pdf into the specified width, preserves aspect ratio (10-131072) |
49 | | `height={n}` | Fits the generated image/pdf into the specified height, preserves aspect ratio (10-131072) |
50 | | `crop=true` | Crops PDF to diagram size |
51 |
52 |
53 | For full API documentation, start up the container and navigate to the `/docs` route with your browser; for example: `http://localhost:5000/docs`
54 |
55 | ## Shout outs
56 |
57 | This would not have been possible without [this post](https://github.com/jgraph/drawio-desktop/issues/127#issuecomment-520053181) from [Joel Martin](https://github.com/kanaka); he resolved most of the hard issues.
58 |
59 | The older versions (before v1.2) were much smaller but had a problem with some fonts, and stopped working when I tried to upgrade the versions of dependencies. Luckily, [Erwan BOUSSE](https://gitlab.univ-nantes.fr/bousse-e) created [a version](https://gitlab.univ-nantes.fr/bousse-e/docker-drawio) of containerized drawio that works. This builds on his approach and retains the simple REST API on top.
60 |
61 | ## Building the container
62 |
63 | ```
64 | docker-compose build
65 | ```
66 |
--------------------------------------------------------------------------------
/docker-compose.test.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | sut:
4 | build:
5 | context: .
6 | dockerfile: Dockerfile.test
7 | command: python -u -m pytest test_server.py
8 | depends_on:
9 | - drawio-renderer
10 | drawio-renderer:
11 | build:
12 | context: .
13 | dockerfile: Dockerfile
14 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | drawio-renderer:
4 | build:
5 | context: .
6 | dockerfile: Dockerfile
7 | image: tomkludy/drawio-renderer:latest
8 | container_name: drawio-renderer
9 | ports:
10 | - "5000:5000"
11 |
--------------------------------------------------------------------------------
/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: Draw.io Renderer
4 | description: |
5 | REST API for rendering diagrams built on [diagrams.net](https://diagrams.net)
6 | (formerly known as [draw.io](https://draw.io)) into images.
7 | version: 1.1.0
8 | servers:
9 | - url: http://localhost:5000/
10 | description: Locally running docker container. See instructions.
11 | paths:
12 | /convert_file:
13 | post:
14 | summary: Convert a diagram to an image
15 | description: |
16 | Convert a diagram to a supported image format.
17 |
18 | Note: The caller must specify the `Accept:` request header with one
19 | of the possible output format MIME types in order to choose
20 | the desired image format.
21 | parameters:
22 | - in: query
23 | name: quality
24 | schema:
25 | type: integer
26 | minimum: 1
27 | maximum: 100
28 | description: 'Output image quality for JPEG (default: 90)'
29 | - in: query
30 | name: transparent
31 | schema:
32 | type: boolean
33 | description: Use transparent background for PNG
34 | - in: query
35 | name: embed
36 | schema:
37 | type: boolean
38 | description: Includes a copy of the diagram (for PNG format only)
39 | - in: query
40 | name: border
41 | schema:
42 | type: integer
43 | minimum: 0
44 | maximum: 10000
45 | description: 'Sets the border width around the diagram (default: 0)'
46 | - in: query
47 | name: scale
48 | schema:
49 | type: number
50 | minimum: 0
51 | exclusiveMinimum: true
52 | maximum: 5
53 | description: Scales the diagram size; 1.0 is default size
54 | - in: query
55 | name: width
56 | schema:
57 | type: integer
58 | minimum: 10
59 | maximum: 10000
60 | description: Fits the generated image/pdf into the specified width, preserves aspect ratio
61 | - in: query
62 | name: height
63 | schema:
64 | type: integer
65 | minimum: 10
66 | maximum: 10000
67 | description: Fits the generated image/pdf into the specified height, preserves aspect ratio
68 | - in: query
69 | name: crop
70 | schema:
71 | type: boolean
72 | description: Crops PDF to diagram size
73 | requestBody:
74 | required: true
75 | content:
76 | application/xml:
77 | schema:
78 | type: string
79 | example: jZLbboMwDIafhstJ0Gwtu13XwyYhTaq0apcp8UikgFFqBvTpF4aBoqrSrrA/H3B+OxDrvNk5WeoEFdhgEaomEK/BYhFF4dJ/OtL2ZBU/9yBzRnHSBA7mAgxDppVRcJ4lEqIlU85hikUBKc2YdA7redo32vlfS5nBDTik0t7So1Gkexo/hRPfg8k0jQ/mSC6HZAZnLRXWV0hsArF2iNRbebMG24k36NLXbe9Ex8EcFPSfgs/T28ldNNmtTd4fd3Hy9dE+cJcfaSt+8N5XoUdHdF6qfnJqBzkcVoWCrmMYiJdaG4JDKdMuWvsD8ExTbr0XeZN7gyNo7g4djVL4GwLMgVzrU7hALFk9Ph+xYr+elhENCuurRQx1kvefja0nibzBKg3utI2/2NVNi80v
80 | application/drawio:
81 | schema:
82 | type: string
83 | example: jZLbboMwDIafhstJ0Gwtu13XwyYhTaq0apcp8UikgFFqBvTpF4aBoqrSrrA/H3B+OxDrvNk5WeoEFdhgEaomEK/BYhFF4dJ/OtL2ZBU/9yBzRnHSBA7mAgxDppVRcJ4lEqIlU85hikUBKc2YdA7redo32vlfS5nBDTik0t7So1Gkexo/hRPfg8k0jQ/mSC6HZAZnLRXWV0hsArF2iNRbebMG24k36NLXbe9Ex8EcFPSfgs/T28ldNNmtTd4fd3Hy9dE+cJcfaSt+8N5XoUdHdF6qfnJqBzkcVoWCrmMYiJdaG4JDKdMuWvsD8ExTbr0XeZN7gyNo7g4djVL4GwLMgVzrU7hALFk9Ph+xYr+elhENCuurRQx1kvefja0nibzBKg3utI2/2NVNi80v
84 | responses:
85 | '200':
86 | $ref: "#/components/responses/Ok"
87 | '400':
88 | $ref: "#/components/responses/BadRequest"
89 | '409':
90 | $ref: "#/components/responses/NotAcceptable"
91 | '413':
92 | $ref: "#/components/responses/EntityTooLarge"
93 | /convert:
94 | post:
95 | summary: Convert a diagram to an image
96 | description: Convert a diagram to a supported image format.
97 | requestBody:
98 | required: true
99 | content:
100 | application/json:
101 | schema:
102 | $ref: '#/components/schemas/Options'
103 | examples:
104 | PNG:
105 | value:
106 | source: jZLbboMwDIafhstJ0Gwtu13XwyYhTaq0apcp8UikgFFqBvTpF4aBoqrSrrA/H3B+OxDrvNk5WeoEFdhgEaomEK/BYhFF4dJ/OtL2ZBU/9yBzRnHSBA7mAgxDppVRcJ4lEqIlU85hikUBKc2YdA7redo32vlfS5nBDTik0t7So1Gkexo/hRPfg8k0jQ/mSC6HZAZnLRXWV0hsArF2iNRbebMG24k36NLXbe9Ex8EcFPSfgs/T28ldNNmtTd4fd3Hy9dE+cJcfaSt+8N5XoUdHdF6qfnJqBzkcVoWCrmMYiJdaG4JDKdMuWvsD8ExTbr0XeZN7gyNo7g4djVL4GwLMgVzrU7hALFk9Ph+xYr+elhENCuurRQx1kvefja0nibzBKg3utI2/2NVNi80v
107 | embed: true
108 | JPEG:
109 | value:
110 | source: jZLbboMwDIafhstJ0Gwtu13XwyYhTaq0apcp8UikgFFqBvTpF4aBoqrSrrA/H3B+OxDrvNk5WeoEFdhgEaomEK/BYhFF4dJ/OtL2ZBU/9yBzRnHSBA7mAgxDppVRcJ4lEqIlU85hikUBKc2YdA7redo32vlfS5nBDTik0t7So1Gkexo/hRPfg8k0jQ/mSC6HZAZnLRXWV0hsArF2iNRbebMG24k36NLXbe9Ex8EcFPSfgs/T28ldNNmtTd4fd3Hy9dE+cJcfaSt+8N5XoUdHdF6qfnJqBzkcVoWCrmMYiJdaG4JDKdMuWvsD8ExTbr0XeZN7gyNo7g4djVL4GwLMgVzrU7hALFk9Ph+xYr+elhENCuurRQx1kvefja0nibzBKg3utI2/2NVNi80v
111 | format: jpeg
112 | quality: 95
113 | SVG:
114 | value:
115 | source: jZLbboMwDIafhstJ0Gwtu13XwyYhTaq0apcp8UikgFFqBvTpF4aBoqrSrrA/H3B+OxDrvNk5WeoEFdhgEaomEK/BYhFF4dJ/OtL2ZBU/9yBzRnHSBA7mAgxDppVRcJ4lEqIlU85hikUBKc2YdA7redo32vlfS5nBDTik0t7So1Gkexo/hRPfg8k0jQ/mSC6HZAZnLRXWV0hsArF2iNRbebMG24k36NLXbe9Ex8EcFPSfgs/T28ldNNmtTd4fd3Hy9dE+cJcfaSt+8N5XoUdHdF6qfnJqBzkcVoWCrmMYiJdaG4JDKdMuWvsD8ExTbr0XeZN7gyNo7g4djVL4GwLMgVzrU7hALFk9Ph+xYr+elhENCuurRQx1kvefja0nibzBKg3utI2/2NVNi80v
116 | format: svg
117 | PDF:
118 | value:
119 | source: jZLbboMwDIafhstJ0Gwtu13XwyYhTaq0apcp8UikgFFqBvTpF4aBoqrSrrA/H3B+OxDrvNk5WeoEFdhgEaomEK/BYhFF4dJ/OtL2ZBU/9yBzRnHSBA7mAgxDppVRcJ4lEqIlU85hikUBKc2YdA7redo32vlfS5nBDTik0t7So1Gkexo/hRPfg8k0jQ/mSC6HZAZnLRXWV0hsArF2iNRbebMG24k36NLXbe9Ex8EcFPSfgs/T28ldNNmtTd4fd3Hy9dE+cJcfaSt+8N5XoUdHdF6qfnJqBzkcVoWCrmMYiJdaG4JDKdMuWvsD8ExTbr0XeZN7gyNo7g4djVL4GwLMgVzrU7hALFk9Ph+xYr+elhENCuurRQx1kvefja0nibzBKg3utI2/2NVNi80v
120 | format: pdf
121 | pages: '0..5'
122 | responses:
123 | '200':
124 | $ref: "#/components/responses/Ok"
125 | '400':
126 | $ref: "#/components/responses/BadRequest"
127 | '409':
128 | $ref: "#/components/responses/NotAcceptable"
129 | '413':
130 | $ref: "#/components/responses/EntityTooLarge"
131 | components:
132 | responses:
133 | Ok:
134 | description: The image was successfully converted and is returned.
135 | content:
136 | image/png:
137 | schema:
138 | type: string
139 | format: binary
140 | example: "\\x89PNG\\x0D\\x0A\\x1A\\x0A..."
141 | image/jpeg:
142 | schema:
143 | type: string
144 | format: binary
145 | example: "\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01..."
146 | application/pdf:
147 | schema:
148 | type: string
149 | format: binary
150 | example: "%PDF-1.4..."
151 | image/svg+xml; encoding=utf-8:
152 | schema:
153 | type: string
154 | example: " %s", infile, outfile)
64 | try:
65 | with open(infile, "wb") as tmp:
66 | tmp.write(source)
67 |
68 | cmd = ['xvfb-run', '-a', '/opt/drawio/drawio', '-x', '-f', fmt, '-o', outfile]
69 | if 'quality' in req:
70 | cmd.extend(['-q', str(req['quality'])])
71 | if 'transparent' in req and req['transparent']:
72 | cmd.append('-t')
73 | if 'embed' in req and req['embed']:
74 | cmd.append('-e')
75 | if 'border' in req:
76 | cmd.extend(['-b', str(req['border'])])
77 | if 'scale' in req:
78 | cmd.extend(['-s', str(req['scale'])])
79 | if 'width' in req:
80 | cmd.extend(['--width', str(req['width'])])
81 | if 'height' in req:
82 | cmd.extend(['--height', str(req['height'])])
83 | if 'crop' in req and req['crop']:
84 | cmd.append('--crop')
85 |
86 | # this must be the next-to-last parameter
87 | cmd.append(infile)
88 |
89 | # this must be the last parameter
90 | cmd.append('--no-sandbox')
91 |
92 | result = subprocess.run(cmd, universal_newlines=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
93 | if len(result.stderr) > 0:
94 | print(result.stderr, file=sys.stderr, end='', flush=True)
95 | error = result.stderr.splitlines()[0]
96 | if 'Out of memory' in error:
97 | code = 413
98 | elif 'Xvfb failed to start' in error:
99 | code = 500
100 | else:
101 | code = 400
102 | return {'message': f'Error executing draw.io: {error}'}, code
103 |
104 | line = result.stdout.splitlines()[-1]
105 | if f" -> {outfile}" not in line:
106 | return {'message': f'Error processing input: {line}'}, 400
107 |
108 | return send_file(outfile, attachment_filename=outbase)
109 | finally:
110 | os.umask(saved_umask)
111 | shutil.rmtree(tmpdir)
112 |
113 | @app.route('/convert', methods=['POST'])
114 | @expects_json(schema, fill_defaults=True)
115 | def convert_json():
116 | req = g.data
117 | source = req['source'].encode('utf-8')
118 | fmt = req['format']
119 | return convert_common(req, source, fmt)
120 |
121 | def try_to_int(req, prop, minimum, maximum):
122 | if prop in req:
123 | try:
124 | val = int(req[prop])
125 | if val < minimum or val > maximum:
126 | return f'{prop} must be an integer from {minimum}-{maximum}'
127 | req[prop] = val
128 | except ValueError:
129 | return f'{prop} must be an integer from {minimum}-{maximum}'
130 | return None
131 |
132 | def try_to_bool(req, prop):
133 | if prop in req:
134 | val = req[prop].lower()
135 | if val == 'true':
136 | req[prop] = True
137 | elif val == 'false':
138 | req[prop] = False
139 | else:
140 | return f'{prop} must be true or false'
141 | return None
142 |
143 | def try_to_float(req, prop, maximum):
144 | if prop in req:
145 | try:
146 | val = float(req[prop])
147 | if val <= 0.0 or val > maximum:
148 | return f'{prop} must be an integer from 0-{maximum}'
149 | req[prop] = val
150 | except ValueError:
151 | return f'{prop} must be an integer from 0-{maximum}'
152 | return None
153 |
154 | @app.route('/convert_file', methods=['POST'])
155 | def convert_file():
156 | req = request.args.copy() if request.args else {}
157 | error = try_to_int(req, 'quality', 1, 100) or \
158 | try_to_bool(req, 'transparent') or \
159 | try_to_bool(req, 'embed') or \
160 | try_to_int(req, 'border', 0, 10000) or \
161 | try_to_float(req, 'scale', 5.0) or \
162 | try_to_int(req, 'width', 10, 131072) or \
163 | try_to_int(req, 'height', 10, 131072) or \
164 | try_to_bool(req, 'crop')
165 | if error: return {'error': error}, 400
166 |
167 | source = request.get_data()
168 |
169 | accept = request.accept_mimetypes
170 | content_types = {
171 | 'image/png': 'png',
172 | 'image/jpeg': 'jpeg',
173 | 'image/svg+xml; charset=utf-8': 'svg',
174 | 'application/pdf': 'pdf'
175 | }
176 | best = accept.best_match(content_types.keys())
177 | if not best in content_types:
178 | return {'error': f"Not Acceptable; must 'Accept:' one of: {list(content_types.keys())}"}, 406
179 |
180 | fmt = content_types[best]
181 | return convert_common(req, source, fmt)
182 |
183 | if __name__ == '__main__':
184 | app.run()
185 |
--------------------------------------------------------------------------------
/test_assets/jpeg_default.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/jpeg_default.jpeg
--------------------------------------------------------------------------------
/test_assets/jpeg_quality_1.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/jpeg_quality_1.jpeg
--------------------------------------------------------------------------------
/test_assets/jpeg_quality_100.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/jpeg_quality_100.jpeg
--------------------------------------------------------------------------------
/test_assets/pdf_crop.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/pdf_crop.pdf
--------------------------------------------------------------------------------
/test_assets/pdf_default.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/pdf_default.pdf
--------------------------------------------------------------------------------
/test_assets/png_border_100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_border_100.png
--------------------------------------------------------------------------------
/test_assets/png_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_default.png
--------------------------------------------------------------------------------
/test_assets/png_embed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_embed.png
--------------------------------------------------------------------------------
/test_assets/png_height_10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_height_10.png
--------------------------------------------------------------------------------
/test_assets/png_height_1000.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_height_1000.png
--------------------------------------------------------------------------------
/test_assets/png_scale_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_scale_5.png
--------------------------------------------------------------------------------
/test_assets/png_scale_point5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_scale_point5.png
--------------------------------------------------------------------------------
/test_assets/png_transparent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_transparent.png
--------------------------------------------------------------------------------
/test_assets/png_width_10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_width_10.png
--------------------------------------------------------------------------------
/test_assets/png_width_1000.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_width_1000.png
--------------------------------------------------------------------------------
/test_assets/png_width_400_height_200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomkludy/docker-drawio-renderer/3dddc81865be3fe4cb3e20c89f905ac4372e8f79/test_assets/png_width_400_height_200.png
--------------------------------------------------------------------------------
/test_assets/svg_default.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test_assets/test_input.drawio:
--------------------------------------------------------------------------------
1 | xZVdb4MgFEB/jY9LBJyur+v6sSVNmjRZs0cqTEhQDKVT++uH81olpsn2sPjk5dwLF45EA7LM642hpdhpxlWAQ1YH5CXAGKEwdo+WNB1JFqgDmZEMigZwkFcOMAR6kYyfvUKrtbKy9GGqi4Kn1mPUGF35ZZ9a+V1LmvEJOKRUTelRMis6ihcjvuUyE9A5QqRL5LSvhYOcBWW6GiGyCsjSaG27KK+XXLXuei3dvPWd7K2/4YX9zYT30+vJXIVVa7V7izZPu4998wCrfFF1gfNu3Szt0FEbZwrHyi3+fDIuytpo3+rCIcw726b3ZPSlYLztFbqySkjLDyVN22zlboZjwubKjZALp3vvN8KN5fUIwVk2XOfcmsaVQDYCrXCtUAzjanhJqFcvRi+or6NwL7LbyoM7F4C+P6jEE5Xgiszu6jHxXEXJ3K7IPVd4dldk4V8sHM4tK7onK5pfVuLLisn/yXLD4WP5kxv9ccjqGw==
--------------------------------------------------------------------------------
/test_server.py:
--------------------------------------------------------------------------------
1 | import requests, re, io, struct, os
2 |
3 | SERVER_ADDRESS="http://drawio-renderer:5000"
4 |
5 | valid_content_types = {
6 | 'png': 'image/png',
7 | 'jpeg': 'image/jpeg',
8 | 'svg': 'image/svg+xml; charset=utf-8',
9 | 'pdf': 'application/pdf',
10 | }
11 |
12 | with open('test_assets/test_input.drawio', 'r') as file:
13 | TEST_INPUT = file.read()
14 |
15 | def expect_error_lambda(f, expected = 400):
16 | response = f()
17 | assert response.status_code == expected
18 | assert response.headers['content-type'] == 'application/json'
19 | rj = response.json()
20 | assert 'error' in rj
21 |
22 | def expect_error(json):
23 | # Try the JSON API
24 | expect_error_lambda(lambda:
25 | requests.post(f"{SERVER_ADDRESS}/convert", json = json))
26 |
27 | # Try the upload API
28 | # first, drop the source/format properties, as they are replaced
29 | # by the request body and the 'Accept' header in the upload API
30 | source = json['source'].encode('utf-8') if 'source' in json else b''
31 | del json['source']
32 | fmt = json.pop('format', 'png')
33 | content_type = valid_content_types[fmt] if fmt in valid_content_types else 'nonsense'
34 |
35 | # now, make the request with the remaining stuff as query params
36 | expect_error_lambda(lambda:
37 | requests.post(f"{SERVER_ADDRESS}/convert_file",
38 | params=json, data = source,
39 | headers = {'accept': content_type}),
40 | 400 if fmt in valid_content_types else 406)
41 |
42 | def pdf_content(content):
43 | # PDFs contain Creator/Producer/CreationDate/ModDate lines
44 | # which won't match, exclude those from comparison
45 | content = re.sub(rb'\/Creator\s*\(.*\)', b'', content)
46 | content = re.sub(rb'\/Producer\s*\(.*\)', b'', content)
47 | content = re.sub(rb'\/CreationDate\s*\(.*\)', b'', content)
48 | content = re.sub(rb'\/ModDate\s*\(.*\)', b'', content)
49 | return content
50 |
51 | def jpeg_content(content):
52 | reader = io.BytesIO(content)
53 | assert reader.read(2) == b"\xff\xd8"
54 | while True:
55 | marker,length = struct.unpack(">2H", reader.read(4))
56 | assert marker & 0xff00 == 0xff00
57 | if marker == 0xFFDA: # Start of stream
58 | return reader.read()
59 | else:
60 | reader.seek(length - 2, os.SEEK_CUR)
61 |
62 | def expect_file_common(response, file_name, content_type):
63 | assert response.status_code == 200
64 | assert response.headers['content-type'] == content_type
65 | with open(file_name, 'rb') as file:
66 | expected = file.read()
67 | actual = response.content
68 |
69 | if content_type == 'application/pdf':
70 | # Comparing PDFs is generally quite complicated; most sources
71 | # recommend converting to another image format and then
72 | # comparing that instead. For now the test will just strip
73 | # metadata from the PDF and then do a binary comparison of
74 | # the rest. This might turn out to be fragile, so if this
75 | # test becomes problematic the more heavyweight approach
76 | # may need to be added later.
77 | expected = pdf_content(expected)
78 | actual = pdf_content(actual)
79 |
80 | if content_type == 'image/jpeg':
81 | # Comparing jpegs is complicated because the metadata
82 | # contains timestamps.
83 | expected = jpeg_content(expected)
84 | actual = jpeg_content(actual)
85 |
86 | assert expected == actual
87 |
88 | def expect_file(json, file_name):
89 | # Try the JSON API
90 | fmt = json['format'] if 'format' in json else 'png'
91 | content_type = valid_content_types[fmt]
92 | response = requests.post(f"{SERVER_ADDRESS}/convert", json = json)
93 | expect_file_common(response, file_name, content_type)
94 |
95 | # Try the upload API
96 | # first, drop the source/format properties, as they are replaced
97 | # by the request body and the 'Accept' header in the upload API
98 | source = json['source'].encode('utf-8')
99 | del json['source']
100 | json.pop('format', None)
101 |
102 | # now, make the request with the remaining stuff as query params
103 | response = requests.post(f"{SERVER_ADDRESS}/convert_file",
104 | params=json, data = source,
105 | headers = {'accept': content_type})
106 | expect_file_common(response, file_name, content_type)
107 |
108 |
109 | def test_get_docs_check_status_equals_200():
110 | response = requests.get(f"{SERVER_ADDRESS}/docs")
111 | assert response.status_code == 200
112 |
113 | def test_not_json_status_equals_400():
114 | expect_error_lambda(lambda:
115 | requests.post(f"{SERVER_ADDRESS}/convert", data = "nonsense!"))
116 |
117 | def test_fake_json_status_equals_400():
118 | expect_error_lambda(lambda:
119 | requests.post(f"{SERVER_ADDRESS}/convert",
120 | data = "nonsense!",
121 | headers = {
122 | 'content-type':'application/json'
123 | }))
124 |
125 | def test_bad_format_status_equals_400_or_406():
126 | expect_error({
127 | 'source': TEST_INPUT,
128 | 'format': 'nonsense!'
129 | })
130 |
131 | def test_defaults():
132 | expect_file({
133 | 'source': TEST_INPUT
134 | }, 'test_assets/png_default.png')
135 |
136 | def test_png_defaults():
137 | expect_file({
138 | 'source': TEST_INPUT,
139 | 'format': 'png',
140 | }, 'test_assets/png_default.png')
141 |
142 | def test_jpeg_defaults():
143 | expect_file({
144 | 'source': TEST_INPUT,
145 | 'format': 'jpeg',
146 | }, 'test_assets/jpeg_default.jpeg')
147 |
148 | def test_svg_defaults():
149 | expect_file({
150 | 'source': TEST_INPUT,
151 | 'format': 'svg',
152 | }, 'test_assets/svg_default.svg')
153 |
154 | def test_pdf_defaults():
155 | expect_file({
156 | 'source': TEST_INPUT,
157 | 'format': 'pdf',
158 | }, 'test_assets/pdf_default.pdf')
159 |
160 | def test_jpeg_quality_0():
161 | expect_error({
162 | 'source': TEST_INPUT,
163 | 'format': 'jpeg',
164 | 'quality': 0,
165 | })
166 |
167 | def test_jpeg_quality_1():
168 | expect_file({
169 | 'source': TEST_INPUT,
170 | 'format': 'jpeg',
171 | 'quality': 1,
172 | }, 'test_assets/jpeg_quality_1.jpeg')
173 |
174 | def test_jpeg_quality_100():
175 | expect_file({
176 | 'source': TEST_INPUT,
177 | 'format': 'jpeg',
178 | 'quality': 100,
179 | }, 'test_assets/jpeg_quality_100.jpeg')
180 |
181 | def test_jpeg_quality_101():
182 | expect_error({
183 | 'source': TEST_INPUT,
184 | 'format': 'jpeg',
185 | 'quality': 101,
186 | })
187 |
188 | def test_png_transparent():
189 | expect_file({
190 | 'source': TEST_INPUT,
191 | 'format': 'png',
192 | 'transparent': True,
193 | }, 'test_assets/png_transparent.png')
194 |
195 | def test_png_embed():
196 | expect_file({
197 | 'source': TEST_INPUT,
198 | 'format': 'png',
199 | 'embed': True,
200 | }, 'test_assets/png_embed.png')
201 |
202 | def test_png_border_neg1():
203 | expect_error({
204 | 'source': TEST_INPUT,
205 | 'format': 'png',
206 | 'border': -1,
207 | })
208 |
209 | def test_png_border_100():
210 | expect_file({
211 | 'source': TEST_INPUT,
212 | 'format': 'png',
213 | 'border': 100,
214 | }, 'test_assets/png_border_100.png')
215 |
216 | def test_png_border_10001():
217 | expect_error({
218 | 'source': TEST_INPUT,
219 | 'format': 'png',
220 | 'border': 10001,
221 | })
222 |
223 | def test_png_scale_0():
224 | expect_error({
225 | 'source': TEST_INPUT,
226 | 'format': 'png',
227 | 'scale': 0,
228 | })
229 |
230 | def test_png_scale_point5():
231 | expect_file({
232 | 'source': TEST_INPUT,
233 | 'format': 'png',
234 | 'scale': 0.5,
235 | }, 'test_assets/png_scale_point5.png')
236 |
237 | def test_png_scale_5():
238 | expect_file({
239 | 'source': TEST_INPUT,
240 | 'format': 'png',
241 | 'scale': 5.0,
242 | }, 'test_assets/png_scale_5.png')
243 |
244 | def test_png_scale_5point1():
245 | expect_error({
246 | 'source': TEST_INPUT,
247 | 'format': 'png',
248 | 'scale': 5.1,
249 | })
250 |
251 | def test_png_width_9():
252 | expect_error({
253 | 'source': TEST_INPUT,
254 | 'format': 'png',
255 | 'width': 9,
256 | })
257 |
258 | def test_png_width_10():
259 | expect_file({
260 | 'source': TEST_INPUT,
261 | 'format': 'png',
262 | 'width': 10,
263 | }, 'test_assets/png_width_10.png')
264 |
265 | def test_png_width_1000():
266 | expect_file({
267 | 'source': TEST_INPUT,
268 | 'format': 'png',
269 | 'width': 1000,
270 | }, 'test_assets/png_width_1000.png')
271 |
272 | def test_png_width_1000000():
273 | expect_error({
274 | 'source': TEST_INPUT,
275 | 'format': 'png',
276 | 'width': 1000000,
277 | })
278 |
279 | def test_png_height_9():
280 | expect_error({
281 | 'source': TEST_INPUT,
282 | 'format': 'png',
283 | 'height': 9,
284 | })
285 |
286 | def test_png_height_10():
287 | expect_file({
288 | 'source': TEST_INPUT,
289 | 'format': 'png',
290 | 'height': 10,
291 | }, 'test_assets/png_height_10.png')
292 |
293 | def test_png_height_1000():
294 | expect_file({
295 | 'source': TEST_INPUT,
296 | 'format': 'png',
297 | 'height': 1000,
298 | }, 'test_assets/png_height_1000.png')
299 |
300 | def test_png_height_1000000():
301 | expect_error({
302 | 'source': TEST_INPUT,
303 | 'format': 'png',
304 | 'height': 1000000,
305 | })
306 |
307 | def test_png_width_400_height_200():
308 | expect_file({
309 | 'source': TEST_INPUT,
310 | 'format': 'png',
311 | 'width': 400,
312 | 'height': 200,
313 | }, 'test_assets/png_width_400_height_200.png')
314 |
315 | def test_pdf_crop():
316 | expect_file({
317 | 'source': TEST_INPUT,
318 | 'format': 'pdf',
319 | 'crop': True,
320 | }, 'test_assets/pdf_crop.pdf')
321 |
--------------------------------------------------------------------------------