Skip to content

Instantly share code, notes, and snippets.

@isurfer21
Last active January 9, 2024 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isurfer21/dbca939e6379e9ae772649a6a55b54aa to your computer and use it in GitHub Desktop.
Save isurfer21/dbca939e6379e9ae772649a6a55b54aa to your computer and use it in GitHub Desktop.
PDF to PNG converter CLI wrapper made using Imagemagick
#!/bin/bash
# This script takes two arguments: input filename and output filename
# It uses imagemagick to convert the input file to a png file with specified options
# Check if the number of arguments is correct
if [ $# -ne 2 ]; then
app_name=${0##*/}
echo "Syntax: $app_name <input> <output>"
echo "Usage: "
echo " $app_name input.pdf output.png"
echo " $app_name '*.pdf' output.png"
exit 1
fi
# Assign the arguments to variables
input_file=$1
output_file=$2
# Run the imagemagick command with the input and output files
magick convert -density 288 "$input_file" "$output_file"
# Check if the conversion was successful
if [ $? -eq 0 ]; then
echo "Conversion successful!"
else
echo "Conversion failed!"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment