Last active
May 8, 2023 16:36
-
-
Save TimothyLoyer/5ec99d06501eddb27b508d5064059b79 to your computer and use it in GitHub Desktop.
Bash script to convert images for use with Supernote A6X and A5X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: [email protected] | |
# 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