Skip to content

Instantly share code, notes, and snippets.

Last active November 16, 2023 18:52
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Makefile to convert images to a pdf suitable for presentatio on reMarkable 2
# Makefile to convert images (JPG or PNG) to a grayscale 4-bit PDF with a custom message, contrast adjustment, 8 levels of gray, and a background image using ImageMagick
# Output PDF file name
OUTPUT = output.pdf
# File containing the list of image filenames
IMAGE_LIST_FILE = slides.txt
# Temporary directory for images with messages
TEMP_DIR = temp_msg
# Custom message to be added at the bottom of each image
MESSAGE = Olivier Wulveryck - OCTO Technology
# Blank image
BLANK = blank.png
# Background image
BACKGROUND = background.png
# SVG files to be converted to PNG
SVG_FILES = $(wildcard *.svg)
PNG_FILES = $(SVG_FILES:.svg=.png)
# # Background image with rounded corners and annotation
BACKGROUND_IMAGE = background.png
# Conversion rule
convert -size 1872x1404 xc:white $(BLANK)
convert -size 1872x1404 xc:white -fill none -stroke gray -strokewidth 60 -draw "roundrectangle 30,30 1842,1374 45,45" rounded.png
convert -background none -fill white -gravity Center -pointsize 20 label:'$(MESSAGE)' label.png
convert rounded.png label.png -gravity South -geometry +0+20 -composite $(BACKGROUND_IMAGE)
rm rounded.png label.png
mkdir -p $(TEMP_DIR)
counter=1; \
while IFS='|' read -r img title; do \
temp_img="$(TEMP_DIR)/temp_$$(printf "%03d" $$counter)_$$(basename $$img)"; \
output_file="$(TEMP_DIR)/$$(printf "%03d" $$counter)_$$(basename $$img)"; \
convert "$$img" -contrast -resize 1752x1284 -background none -gravity center -extent 1752x1284 -colorspace Gray -colors 8 "$$temp_img"; \
convert -background none -fill white -gravity Center -pointsize 20 label:"$$title" label.png; \
convert $(BACKGROUND_IMAGE) label.png -gravity North -geometry +0+20 -composite slide.png; \
composite -gravity center "$$temp_img" slide.png "$$output_file"; \
rm "$$temp_img" label.png slide.png; \
counter=$$((counter + 1)); \
convert -units PixelsPerInch -density 150x150 $(TEMP_DIR)/* $@
rm -rf $(TEMP_DIR)
svg2png: $(PNG_FILES)
%.png: %.svg
convert $< $@
.PHONY: all clean svg2png
front.png|This title is displayed on top
blank.png|This a blank slide with this title
Copy link

owulveryck commented Oct 6, 2023

To use this,

  • Place the Makefile and the images in a directory.
    Create a slides.txt file with one filename per line and an optional title separated by a |.
    You can add blank.png to add a blank page, and add the same files multiple times.

  • run make

  • transfer output.pdf to the remarkable

Copy link

More about the why on my blog Rethinking Presentations: Beyond Static Slides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment