Hello World

Image Slicing

Overview

In Emacs, displaying an image occupies one line regardless of its height. The movement over the image while navigating by lines can be quite frustrating.

Although pixel-scroll and iscroll have improved image movement to some extent.

I hope to move images in the same way as moving text, line by line.

So I created this package to horizontally slice the images referenced in the buffer into multiple images. In Emacs, only a portion of the original image is displayed on each line. Finally, the image can be moved line by line.

During the development process, I found org-sliced-images which was almost the same as my idea. And thanks to him for letting me know about insert-sliced-image in Emacs.

Prerequisites

CLI

Curl: Used to download remote images.

Require Packages

Install

git clone [email protected]:ginqi7/image-slicing.git ~/.emacs.d/lisp/image-slicing
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/d/lisp/image-slicing"))

Configuration

Here are a few variables that can be used for configuration:

(require 'image-slicing)

Variables

variable default value explain
image-slicing-download-concurrency 20 the maximum concurrency of images download
image-slicing-line-height-scale 2 how many line height an image slice occupies
image-slicing-max-width 700 the maximum width of images display
image-slicing-cursor-fringe-bitmaps '(left-fringe right-arrow warning) the Fringe Bitmaps indicator for the cursor position.1

EWW Config

  1. cancel the eww defualt image render.
(add-to-list 'shr-external-rendering-functions
             '(img . image-slicing-tag-img))
  1. Add image-slicing to eww-after-render-hook
(push #'image-slicing-mode eww-after-render-hook)

Elfeed Config

image-slice can also work with elfeed:

;; add to shr-external-rendering-functions (skip if alread setup for eww)
(add-to-list 'shr-external-rendering-functions
             '(img . image-slicing-tag-img))

;; advice `elfeed-show-entry' to trigger `image-slicing-mode'
(advice-add #'elfeed-show-entry :after #'image-slicing-mode)

Features

Example

Disadvantages

Todo List

Development History

Dec 18, 2024

I find a similar package named org-sliced-images, so I study some code from it to make my code simpler.

In Emacs, we can display a part of an image by using ('display . (list (list 'slice x y dx dy) image)), without needing to actually slice the image using ImageMagick, so I remove the dependency about ImageMagick.

Dec 16, 2024

There have some issues in last version:

  1. There is slow when ImageMagick handle remote images.
  2. Though I will delete the placeholders when the user removes the overlays, there is still a risk of polluting the users' buffer.

So I use asynchronous processes to run ImageMagick, guaranteeing that it will not freeze Emacs. On the other hand, I removed the placeholder and just placed some overlays on the original URL text.

May 12, 2023

I got the idea to slice the image into many pieces, making Emacs display the pieces line by line.

  1. Use the CLI ImageMagick to slice images.
  2. Insert some special text like "#_#_@@_#_#" as placeholder, and put an overlay on that placeholder to show image pieces.

Footnotes


  1. Emacs Fringe Bitmaps↩︎

  • Previous: Project Hail Mary Reading Notes
  • Next: Emacs Brew Manager