|
17 | 17 | from resizeimage.imageexceptions import ImageSizeError |
18 | 18 |
|
19 | 19 | from zimscraperlib.image import presets |
20 | | -from zimscraperlib.image.conversion import convert_image, create_favicon |
| 20 | +from zimscraperlib.image.conversion import ( |
| 21 | + convert_image, |
| 22 | + convert_svg2png, |
| 23 | + create_favicon, |
| 24 | +) |
21 | 25 | from zimscraperlib.image.optimization import ( |
22 | 26 | ensure_matches, |
23 | 27 | get_optimization_method, |
@@ -328,6 +332,42 @@ def test_convert_path_src_io_dst(png_image: pathlib.Path): |
328 | 332 | assert dst_image.format == "PNG" |
329 | 333 |
|
330 | 334 |
|
| 335 | +def test_convert_svg_io_src_path_dst(svg_image: pathlib.Path, tmp_path: pathlib.Path): |
| 336 | + src = io.BytesIO(svg_image.read_bytes()) |
| 337 | + dst = tmp_path / "test.png" |
| 338 | + convert_svg2png(src, dst) |
| 339 | + dst_image = Image.open(dst) |
| 340 | + assert dst_image.format == "PNG" |
| 341 | + |
| 342 | + |
| 343 | +def test_convert_svg_io_src_io_dst(svg_image: pathlib.Path): |
| 344 | + src = io.BytesIO(svg_image.read_bytes()) |
| 345 | + dst = io.BytesIO() |
| 346 | + convert_svg2png(src, dst) |
| 347 | + dst_image = Image.open(dst) |
| 348 | + assert dst_image.format == "PNG" |
| 349 | + |
| 350 | + |
| 351 | +def test_convert_svg_path_src_path_dst(svg_image: pathlib.Path, tmp_path: pathlib.Path): |
| 352 | + src = svg_image |
| 353 | + dst = tmp_path / "test.png" |
| 354 | + convert_svg2png(src, dst, width=96, height=96) |
| 355 | + dst_image = Image.open(dst) |
| 356 | + assert dst_image.format == "PNG" |
| 357 | + assert dst_image.width == 96 |
| 358 | + assert dst_image.height == 96 |
| 359 | + |
| 360 | + |
| 361 | +def test_convert_svg_path_src_io_dst(svg_image: pathlib.Path): |
| 362 | + src = svg_image |
| 363 | + dst = io.BytesIO() |
| 364 | + convert_svg2png(src, dst, width=96, height=96) |
| 365 | + dst_image = Image.open(dst) |
| 366 | + assert dst_image.format == "PNG" |
| 367 | + assert dst_image.width == 96 |
| 368 | + assert dst_image.height == 96 |
| 369 | + |
| 370 | + |
331 | 371 | @pytest.mark.parametrize( |
332 | 372 | "fmt,exp_size", |
333 | 373 | [("png", 128), ("jpg", 128)], |
|
0 commit comments