From 512e4f8b259ea12808dc98a2f063906b9abd0dff Mon Sep 17 00:00:00 2001 From: Sami Kankaristo Date: Wed, 29 Dec 2021 16:53:49 +0200 Subject: Add rsvg-convert for SVG previews `rsvg-convert` works much more reliably for SVGs than ImageMagick's `convert`, which freezes with large SVGs (seems to convert formats first, and resize only after that), and can drop out text during the conversion. Support for SVGs isn't great in ImageMagick, since it's a raster graphics program. `rsvg-convert` only supports conversion to PNG. The image preview works fine with PNGs, but Ranger assumes/requires a .jpg extension, so the file is just renamed from `xxx.jpg.png` to `xxx.jpg`. It's a bit of an ugly hack, but it works, and it's faster than a second image conversion from PNG to JPEG (and vector graphics usually look better with PNG than with JPEG, which is meant more for photos). On Ubuntu and Debian, `rsvg-convert` is in the `librsvg2-bin` package. --- ranger/data/scope.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ranger') diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 0c003399..9d9d9500 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -132,9 +132,10 @@ handle_image() { local mimetype="${1}" case "${mimetype}" in ## SVG - # image/svg+xml|image/svg) - # convert -- "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6 - # exit 1;; + image/svg+xml|image/svg) + rsvg-convert --keep-aspect-ratio --width "${DEFAULT_SIZE%x*}" "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}.png" \ + && mv "${IMAGE_CACHE_PATH}.png" "${IMAGE_CACHE_PATH}" \ + && exit 6 ## DjVu # image/vnd.djvu) -- cgit 1.4.1-2-gfad0