Skip to content

Commit

Permalink
get rid of svg images
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Jun 2, 2024
1 parent ff921eb commit 3eb464d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions application/lib/calibre/web/fetch/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self, options, fs, log, job_info=None, image_map=None, css_map=None
self.fs = fs
fs.makedirs(self.base_dir)
self.log = log
self.options = options
self.verbose = options.verbose
self.timeout = options.timeout or 60
self.encoding = options.encoding
Expand Down Expand Up @@ -180,7 +181,6 @@ def __init__(self, options, fs, log, job_info=None, image_map=None, css_map=None
self.scale_news_images = getattr(options, 'scale_news_images', None)
self.get_delay = getattr(options, 'get_delay', None)
self.download_stylesheets = not options.no_stylesheets
self.keep_images = options.keep_images
self.show_progress = False
self.failed_links = []
self.job_info = job_info
Expand Down Expand Up @@ -407,7 +407,7 @@ def rescale_image(self, data, itype='jpeg'):
return rescale_image(data, self.scale_news_images, self.compress_news_images_max_size, self.compress_news_images_auto_size, itype=itype)

def process_images(self, soup, baseurl):
if not self.keep_images:
if not getattr(self.options, 'keep_images'):
for tag in soup.find_all('img'):
tag.decompose()
return
Expand Down Expand Up @@ -461,11 +461,14 @@ def process_images(self, soup, baseurl):
itype = what(None, data)
if itype == 'svg' or (itype is None and b'<svg' in data[:1024]):
# SVG image
imgpath = os.path.join(diskpath, fname+'.svg')
with self.imagemap_lock:
self.imagemap[iurl] = imgpath
self.fs.write(imgpath, data, 'wb')
tag['src'] = imgpath
if getattr(self.options, 'keep_svg'):
imgpath = os.path.join(diskpath, fname+'.svg')
with self.imagemap_lock:
self.imagemap[iurl] = imgpath
self.fs.write(imgpath, data, 'wb')
tag['src'] = imgpath
else:
tag.extract()
else:
from calibre.utils.img import image_from_data, image_to_data
try:
Expand Down

0 comments on commit 3eb464d

Please sign in to comment.