Skip to content

Instantly share code, notes, and snippets.

@owulveryck
Last active March 29, 2024 15:58
Show Gist options
  • Save owulveryck/1317f9b22433aa18778b673000159141 to your computer and use it in GitHub Desktop.
Save owulveryck/1317f9b22433aa18778b673000159141 to your computer and use it in GitHub Desktop.

Revisions

  1. owulveryck revised this gist Oct 13, 2023. 2 changed files with 8 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ IMAGE_LIST_FILE = slides.txt
    TEMP_DIR = temp_msg

    # Custom message to be added at the bottom of each image
    MESSAGE = Olivier Wulveryck - 2023
    MESSAGE = Olivier Wulveryck - OCTO Technology

    # Blank image
    BLANK = blank.png
    @@ -41,12 +41,14 @@ $(BACKGROUND_IMAGE):
    $(OUTPUT): $(IMAGE_LIST_FILE) $(BACKGROUND_IMAGE) svg2png
    mkdir -p $(TEMP_DIR)
    counter=1; \
    while IFS= read -r img; do \
    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"; \
    composite -gravity center "$$temp_img" $(BACKGROUND_IMAGE) "$$output_file"; \
    rm "$$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)); \
    done < $(IMAGE_LIST_FILE)
    convert -units PixelsPerInch -density 150x150 $(TEMP_DIR)/* $@
    2 changes: 2 additions & 0 deletions slides.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    front.png|This title is displayed on top
    blank.png|This a blank slide with this title
  2. owulveryck revised this gist Oct 6, 2023. No changes.
  3. owulveryck revised this gist Oct 6, 2023. 1 changed file with 21 additions and 8 deletions.
    29 changes: 21 additions & 8 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Makefile to convert images (JPG or PNG) to a grayscale 4-bit PDF with a custom message using ImageMagick
    # 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
    @@ -10,41 +10,54 @@ IMAGE_LIST_FILE = slides.txt
    TEMP_DIR = temp_msg

    # Custom message to be added at the bottom of each image
    MESSAGE = Olivier Wulveryck
    MESSAGE = Olivier Wulveryck - 2023

    # 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
    all: $(BLANK) $(OUTPUT)
    all: $(BLANK) $(OUTPUT) $(BACKGROUND_IMAGE)


    $(BLANK):
    convert -size 1872x1404 xc:white $(BLANK)

    $(OUTPUT): $(IMAGE_LIST_FILE)
    $(BACKGROUND_IMAGE):
    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

    $(OUTPUT): $(IMAGE_LIST_FILE) $(BACKGROUND_IMAGE) svg2png
    mkdir -p $(TEMP_DIR)
    counter=1; \
    while IFS= read -r img; do \
    temp_img="$(TEMP_DIR)/temp_$$(printf "%03d" $$counter)_$$(basename $$img)"; \
    output_file="$(TEMP_DIR)/$$(printf "%03d" $$counter)_$$(basename $$img)"; \
    convert "$$img" -contrast -resize 1872x1404 -background white -gravity center -extent 1872x1404 -colorspace Gray -colors 8 -gravity SouthWest -pointsize 24 -annotate +10+10 '$(MESSAGE)' "$$output_file"; \
    convert "$$img" -contrast -resize 1752x1284 -background none -gravity center -extent 1752x1284 -colorspace Gray -colors 8 "$$temp_img"; \
    composite -gravity center "$$temp_img" $(BACKGROUND_IMAGE) "$$output_file"; \
    rm "$$temp_img"; \
    counter=$$((counter + 1)); \
    done < $(IMAGE_LIST_FILE)
    convert -units PixelsPerInch -density 150x150 $(TEMP_DIR)/* $@
    rm -rf $(TEMP_DIR)


    svg2png: $(PNG_FILES)

    %.png: %.svg
    convert $< $@

    clean:
    rm -f $(OUTPUT) $(BLANK)
    rm -f $(OUTPUT) $(BLANK) $(PNG_FILES)

    .PHONY: all clean
    .PHONY: all clean svg2png
  4. owulveryck revised this gist Oct 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ IMAGE_LIST_FILE = slides.txt
    TEMP_DIR = temp_msg

    # Custom message to be added at the bottom of each image
    MESSAGE = Olivier Wulveryck - OCTO Technology
    MESSAGE = Olivier Wulveryck

    # Blank image
    BLANK = blank.png
  5. owulveryck created this gist Oct 6, 2023.
    50 changes: 50 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    # Makefile to convert images (JPG or PNG) to a grayscale 4-bit PDF with a custom message 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


    # SVG files to be converted to PNG
    SVG_FILES = $(wildcard *.svg)
    PNG_FILES = $(SVG_FILES:.svg=.png)


    # Conversion rule
    all: $(BLANK) $(OUTPUT)

    $(BLANK):
    convert -size 1872x1404 xc:white $(BLANK)

    $(OUTPUT): $(IMAGE_LIST_FILE)
    mkdir -p $(TEMP_DIR)
    counter=1; \
    while IFS= read -r img; do \
    output_file="$(TEMP_DIR)/$$(printf "%03d" $$counter)_$$(basename $$img)"; \
    convert "$$img" -contrast -resize 1872x1404 -background white -gravity center -extent 1872x1404 -colorspace Gray -colors 8 -gravity SouthWest -pointsize 24 -annotate +10+10 '$(MESSAGE)' "$$output_file"; \
    counter=$$((counter + 1)); \
    done < $(IMAGE_LIST_FILE)
    convert -units PixelsPerInch -density 150x150 $(TEMP_DIR)/* $@
    rm -rf $(TEMP_DIR)


    svg2png: $(PNG_FILES)

    %.png: %.svg
    convert $< $@

    clean:
    rm -f $(OUTPUT) $(BLANK)

    .PHONY: all clean