move move old scripts

This commit is contained in:
lucas committed 2026-10-16 14:00:42 +00:00
1 parent 93b262977b
commit 208fbd96b4
27 files changed
+346

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Convert the first page of a PDF to a JPEG image.
# Usage: ./pdf_to_jpg.sh <file.pdf>
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <file.pdf>"
exit 1
fi
INPUT_PDF="$1"
if [[ ! -f "$INPUT_PDF" ]]; then
echo "Error: '$INPUT_PDF' not found."
exit 1
fi
# Remove .pdf extension and prepend IMG_
BASE_NAME="$(basename "$INPUT_PDF" .pdf)"
OUTPUT_JPG="IMG_${BASE_NAME}.jpg"
echo "Converting first page of '$INPUT_PDF' to '$OUTPUT_JPG'..."
pdftoppm -f 1 -l 1 "$INPUT_PDF" | pnmtojpeg > "$OUTPUT_JPG"
echo "Done: $OUTPUT_JPG created."
+102
View File
@@ -0,0 +1,102 @@
#!/bin/bash
# Convert a PDF into processed JPG images and split them into
# multiple PDF files, with a maximum of 100 images per output PDF.
set -e
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <pdf-file>"
exit 1
fi
pdf_file="$1"
if [ ! -f "$pdf_file" ]; then
echo "Error: '$pdf_file' does not exist."
exit 1
fi
echo "Using $pdf_file"
# Resolve the input directory and filename.
pdf_dir="$(cd "$(dirname "$pdf_file")" && pwd)"
pdf_name="$(basename "$pdf_file")"
base_name="${pdf_name%.*}"
buffer_dir="$pdf_dir/.BUFFERFOLDER"
# Recreate the temporary working directory.
rm -rf "$buffer_dir"
mkdir -p "$buffer_dir"
cp "$pdf_file" "$buffer_dir/$pdf_name"
cd "$buffer_dir"
echo "Extracting images..."
# Extract PDF images as PNG.
pdfimages -png "$pdf_name" "$base_name"
count=0
shopt -s nullglob
for img in *.png; do
jpg="${img%.png}.jpg"
echo "Processing $jpg"
# PNG -> JPG
convert "$img" "$jpg"
rm "$img"
# Normalize image dimensions.
convert "$jpg" -resize 2550x3300! "$jpg"
# Use different crop dimensions for images containing "000".
if [[ "$jpg" == *000* ]]; then
convert "$jpg" -crop 2206x3200+200+50 "$jpg"
else
convert "$jpg" -crop 2106x3200+200+50 "$jpg"
fi
# Remove white background.
convert "$jpg" -fuzz 20% -transparent White "$jpg"
# Center image on a white 2550x3300 canvas.
convert "$jpg" \
-resize 2550x3300 \
-gravity center \
-background White \
-extent 2550x3300 \
"$jpg"
# Group images into batches of 100.
split_var=$((count / 100))
split_dir="split_${split_var}"
mkdir -p "$split_dir"
mv "$jpg" "$split_dir/"
((count++)) || true
done
# Convert each group of images into a PDF.
for split_dir in split_*; do
[ -d "$split_dir" ] || continue
split_number="${split_dir#split_}"
echo "Converting Part $split_number"
convert "$split_dir"/*.jpg \
"$pdf_dir/${base_name}_split_${split_number}.pdf"
done
# Remove temporary files.
cd "$pdf_dir"
rm -rf "$buffer_dir"
echo "Done."