Add image conversion backends

This commit is contained in:
Vinayak Mehta
2021-06-28 01:58:45 +05:30
parent fdade4502e
commit 8563a09544
6 changed files with 80 additions and 38 deletions
+3
View File
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from .image_conversion import ImageConversionBackend
+17
View File
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
import ghostscript
class GhostscriptBackend(object):
def convert(self, pdf_path, png_path, resolution=300):
gs_args = [
"gs",
"-q",
"-sDEVICE=png16m",
"-o",
png_path,
f"-r{resolution}",
pdf_path,
]
ghostscript.Ghostscript(*gs_args)
+15
View File
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from .poppler_backend import PopplerBackend
from .ghostscript_backend import GhostscriptBackend
backends = {"poppler": PopplerBackend, "ghostscript": GhostscriptBackend}
class ImageConversionBackend(object):
def __init__(self, backend="poppler"):
self.backend = backend
def convert(self, pdf_path, png_path):
converter = backends[self.backend]()
converter.convert(pdf_path, png_path)
+8
View File
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from pdftopng import pdftopng
class PopplerBackend(object):
def convert(self, pdf_path, png_path):
pdftopng.convert(pdf_path, png_path)