Skip to content

Instantly share code, notes, and snippets.

@TimothyLoyer
Last active May 8, 2023 16:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimothyLoyer/5ec99d06501eddb27b508d5064059b79 to your computer and use it in GitHub Desktop.
Save TimothyLoyer/5ec99d06501eddb27b508d5064059b79 to your computer and use it in GitHub Desktop.
Bash script to convert images for use with Supernote A6X and A5X
#!/usr/bin/bash
################################################################################
#
# Description:
# Convert images for compatibility with the Supernote A6X and A5X.
#
# If an original image's size exceeds the ratio required to be compatible
# with the Supernote, it will automatically be centered and cropped.
#
# Usage:
# sn-convert-img path/to/img.ext
#
# Requirements:
# • imagemagick [https://imagemagick.org]
#
# Installation:
# • Install imagemagick [https://imagemagick.org/script/download.php]
# • Copy script into your PATH
# • Make sure the script is executable (i.e. `chmod +x <this script>`)
#
# Author:
# Name: Tim Loyer
# Email: tim.loyer@gmail.com
# GitHub Profile: https://github.com/TimothyLoyer
#
################################################################################
# Bash strict mode.
set -euo pipefail
# Prefix to add to the output file. This is helpful when the source image
# format is .png to avoid overwriting the source file.
output_prefix="sn-"
# Required settings for compatibility with Supernote.
sn_dimensions="1404x1872"
sn_format="png"
# Rename the input argument, which should be a source file.
path=$1
# Get the file name from the input path.
input_file=${path##*/}
# Generate a filename for the converted image.
output_file="${output_prefix}${input_file%.*}.${sn_format}"
echo "Converting ${input_file} to Supernote compatible size and format…"
# Convert using imagemagick
convert "${path}" -resize ${sn_dimensions}^ -gravity center -extent ${sn_dimensions} "${output_file}"
echo "Conversion complete as ${output_file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment