about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorSami Kankaristo <sami@kankaristo.fi>2021-12-29 16:53:49 +0200
committerGitHub <noreply@github.com>2021-12-29 16:53:49 +0200
commit512e4f8b259ea12808dc98a2f063906b9abd0dff (patch)
treef60ef00a606a9e27a87e67d7f15f329acbd8e00d /ranger
parent7cbdd92a66e5f0d08672b4b9fc36492a7dc1eed6 (diff)
downloadranger-512e4f8b259ea12808dc98a2f063906b9abd0dff.tar.gz
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.
Diffstat (limited to 'ranger')
-rwxr-xr-xranger/data/scope.sh7
1 files changed, 4 insertions, 3 deletions
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)