Site icon Random Thoughts

Cropping Images in Emacs

I woke up in the middle of the night and started thinking about cropping images in Emacs, as one does. I started wondering how Emacs processed mouse events, and that turns out to be very easy: You just use `read-event’ inside a `track-mouse’ form, and you get all the events and coordinates, offset from the window or the image under point, which is just perfect for my use case here.

 

So after work today, I started typing, and there it is.

Now, cropping an image in Emacs is one thing, but the other is… what do you do with the result? I mean, just displaying the cropped image is nice, but pretty useless. I mean, you can save it, I guess, and that would make sense from an `image-mode’ context. But more generally useful would be from a document composition mode, so I just stuck it into the package for editing WordPress posts.

Behold!

I think it may make sense to factor this out into its own little package so that it can be used elsewhere, but I don’t really have the time at the moment, so I guess it’ll have to wait…

The code is up on Microsoft Github as usual.

Exit mobile version