Add image conversion backends
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from .image_conversion import ImageConversionBackend
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user