Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0 # get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: /secrets
- id: check-added-large-files
- id: check-yaml
args:
- '--allow-multiple-documents'
exclude: /templates|/secrets
- id: check-json

- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0 # Get the latest from: https://github.com/gitleaks/gitleaks/releases
hooks:
- id: gitleaks
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The script currently can add borders, and write EXIF text below the photo; As we
The script uses [ImageMagic®](https://www.imagemagick.org) mainly, [ExifTool](https://www.sno.phy.queensu.ca/~phil/exiftool/) is also needed if you want to remove EXIF from the photo itself, both of them can be install via [Homebrew](https://brew.sh/):

```
brew install imagemagic
brew install imagemagick
brew install exiftool
```

Expand Down Expand Up @@ -64,12 +64,28 @@ add border around photo.jpg, the border is 5% of image width and 10% of image he

**add EXIF on border**

add specified EXIF information at bottom right of image border, medium font size
add specified EXIF information at bottom left of image border, medium font size

```
./bor.sh -b 5%x10% -e cameramodel,focallength,fnumber,exptime,isospeed,stripexif -f medium photo.jpg
```

**add CUSTOM TEXT (Title) on border**

add Photo Title information at top centre of image border, medium font size

```
./bor.sh -b 5%x10% -e cameramodel,focallength,fnumber,exptime,isospeed,stripexif -f medium -t "my title" photo.jpg
```

**add COPYRIGHT on border**

add COPYRIGHT information at bottom right of image border, medium font size

```
./bor.sh -b 5%x10% -e cameramodel,focallength,fnumber,exptime,isospeed,stripexif -f medium -c "my name" photo.jpg
```

Possible font sizes:

* small: font size that is 20% of border size
Expand All @@ -88,7 +104,7 @@ Possible EXIF data (separated by comma when specified for -e):
**Example with all options specified**

```
./bor.sh -b 5%x10% -e cameramodel,focallength,fnumber,exptime,isospeed,stripexif -f medium -r 80% -q 70 photo.jpg photo_output.jpg
./bor.sh -d -b 5%x10% -e cameramodel,focallength,fnumber,exptime,isospeed,stripexif -f medium-t "my title" -c "my name" -r 80% -q 70 photo.jpg photo_output.jpg
```

## run_for_all.sh
Expand Down Expand Up @@ -117,4 +133,4 @@ photo009_bor.jpg

![Generated photo](./photo_output.jpg "Generate photo")

I'll keep improving this script, please let me know how you think.
I'll keep improving this script, please let me know what you think.
88 changes: 65 additions & 23 deletions bor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ ARGS_ANNOTATION_TEXT=
ARGS_EXIF_OPTIONS=
ARGS_FONT_SIZE="medium"
ARGS_CUSTOM_TEXT=
ARGS_COPYRIGHT=
DEBUG_ENABLED=""

usage() {
echo "Usage:"
echo "`basename $0` [-b border options] [-d](enable debug output) [-e EXIF options] [-f (small|medium|large)] [-q quality] [-r resize options] [-t custom text] input_file [output_file]"
echo "`basename $0` [-b border options] [-d](enable debug output) [-e EXIF options] [-f (small|medium|large)] [-q quality] [-r resize options] [-t custom text] [-c copyright] input_file [output_file]"
}

decho() {
Expand All @@ -25,37 +26,62 @@ apply_exif_annotation()
{
if [ $# -eq 2 ]; then
decho "Apply exif annotation: $1 for $2"
declare `convert -ping "$2" -format "cameramodel=%[EXIF:model]\n focallength=%[EXIF:FocalLength]\n fnumber=%[EXIF:FNumber]\n exptime=%[EXIF:ExposureTime]\n isospeed=%[EXIF:PhotographicSensitivity]\n" info:`
# declare `magick -ping "$2" -format "cameramodel=%[EXIF:model]\n focallength=%[EXIF:FocalLength]\n fnumber=%[EXIF:FNumber]\n exptime=%[EXIF:ExposureTime]\n isospeed=%[EXIF:PhotographicSensitivity]\n" info:`
declare `identify -format "focallength=%[EXIF:FocalLength]\n fnumber=%[EXIF:FNumber]\n exptime=%[EXIF:ExposureTime]\n isospeed=%[EXIF:PhotographicSensitivity]\n" "$2"`
# use a separate `identify` to accomodate for spaces in the camera model and lens model
cameramodel=`identify -format '%[EXIF:Model]' "$2"`
# ImageMagick doesn't find lens info, use exiftool instead
if [ -z "$lensmodel" ] && command -v exiftool >/dev/null 2>&1; then
lensmodel=`exiftool -s -s -s -LensID "$2" 2>/dev/null`
if [ -z "$lensmodel" ]; then
lensmodel=`exiftool -s -s -s -Lens "$2" 2>/dev/null`
fi
fi
decho "cameramodel: $cameramodel"
decho "lensmodel: $lensmodel"
fnumber1=`echo $fnumber | cut -d/ -f1`
fnumber2=`echo $fnumber | cut -d/ -f2`
fnumber=`echo "scale=1; $fnumber1/$fnumber2" | bc`
decho "exptime RAW: $exptime"
exptime1=`echo $exptime | cut -d/ -f1`
exptime2=`echo $exptime | cut -d/ -f2`
exptime=`echo "scale=0; $exptime2/$exptime1" | bc`
if [[ $exptime1 -ge $exptime2 ]]; then
# shutterspeed >= 1 sec
exptime=`echo "scale=1; $exptime" | bc`
exptime=`echo "$exptime"`
else
# shutterspeed < 1 sec
exptime=`echo "scale=0; $exptime2/$exptime1" | bc`
exptime=`echo "1/$exptime"`
fi
decho "exptime for printing: $exptime"
fl1=`echo $focallength | cut -d/ -f1`
fl2=`echo $focallength | cut -d/ -f2`
focallength=`echo "scale=0; $fl1/$fl2" | bc`
exiftext=`echo "$cameramodel $focallength, F$fnumber, 1/$exptime, ISO $isospeed"`

exiftext=`echo "$cameramodel, $lensmodel, $focallength, $fnumber, $exptime, $isospeed"`
decho "EXIF: $exiftext"

EXIF_FORMAT=""
EXIF_OPTIONS=$1

if [[ "$EXIF_OPTIONS" == *cameramodel* ]]; then
EXIF_FORMAT="$cameramodel"
fi
if [[ "$EXIF_OPTIONS" == *lensmodel* ]]; then
if [ ! -z "$lensmodel" ]; then
EXIF_FORMAT="${EXIF_FORMAT} / ${lensmodel}"
fi
fi
if [[ "$EXIF_OPTIONS" == *focallength* ]]; then
EXIF_FORMAT="${EXIF_FORMAT} ${focallength}mm"
EXIF_FORMAT="${EXIF_FORMAT} @ ${focallength}mm"
fi
if [[ "$EXIF_OPTIONS" == *fnumber* ]]; then
EXIF_FORMAT="${EXIF_FORMAT} F/${fnumber}"
EXIF_FORMAT="${EXIF_FORMAT}, f/${fnumber}"
fi
if [[ "$EXIF_OPTIONS" == *exptime* ]]; then
EXIF_FORMAT="${EXIF_FORMAT} 1/${exptime}"
EXIF_FORMAT="${EXIF_FORMAT}, ${exptime}sec"
fi
if [[ "$EXIF_OPTIONS" == *isospeed* ]]; then
EXIF_FORMAT="${EXIF_FORMAT} ISO ${isospeed}"
EXIF_FORMAT="${EXIF_FORMAT}, ISO ${isospeed}"
fi
if [[ "$EXIF_OPTIONS" == *stripexif* ]]; then
ARGS_STRIP_EXIF="Y"
Expand All @@ -76,9 +102,7 @@ apply_exif_annotation()
# [[ ! -z "$BOR_QUALITY" ]] && ARGS_QUALITY=$BOR_QUALITY
# [[ ! -z "$BOR_BORDER" ]] && ARGS_BORDER=$BOR_BORDER
# [[ ! -z "$BOR_COLOR" ]] && ARGS_BORDERCOLOR=$BOR_COLOR

# [[ ! -z "$BOR_ANNOTATION_TEXT" ]] && ARGS_ANNOTATION_TEXT=$BOR_ANNOTATION_TEXT

# if [ ! -z "$BOR_EXIF_OPTIONS" ]; then
# ARGS_EXIF_OPTIONS=$BOR_EXIF_OPTIONS
# fi
Expand All @@ -90,7 +114,7 @@ if [ $# -eq 0 ]; then
exit
fi

while getopts :b:de:f:q:r:t: OPTION
while getopts :b:de:f:q:r:t:c: OPTION
do
case $OPTION in
b)
Expand All @@ -115,6 +139,9 @@ do
t)
ARGS_CUSTOM_TEXT=$OPTARG
;;
c)
ARGS_COPYRIGHT=$OPTARG
;;
\?)
usage
;;
Expand All @@ -138,15 +165,18 @@ OUTPUT_FILE=$2
FILE_EXTENSION="${INPUT_FILE##*.}"

if [ ! -z "$ARGS_EXIF_OPTIONS" ]; then
apply_exif_annotation $ARGS_EXIF_OPTIONS $INPUT_FILE
decho "Calling apply_exif_annotation with options: $ARGS_EXIF_OPTIONS for file: $INPUT_FILE"
apply_exif_annotation "$ARGS_EXIF_OPTIONS" "$INPUT_FILE"
else
decho "ARGS_EXIF_OPTIONS is empty, skipping EXIF annotation"
fi

if [ -z "$OUTPUT_FILE" ]; then
OUTPUT_FILE="${INPUT_FILE%.*}_bor.${FILE_EXTENSION}"
echo "No output file specified, use default output file: $OUTPUT_FILE"
fi

COMMAND="convert $INPUT_FILE "
COMMAND="magick $INPUT_FILE "

if [ ! -z "$ARGS_RESIZE" ]; then
COMMAND="${COMMAND} -resize ${ARGS_RESIZE} "
Expand All @@ -170,7 +200,7 @@ if [ ! -z "$ARGS_BORDER" ]; then
if [ -z "$ARGS_BORDERCOLOR" ]; then
ARGS_BORDERCOLOR="White"
fi
COMMAND="convert ${INPUT_FILE} -bordercolor ${ARGS_BORDERCOLOR} -border ${ARGS_BORDER} ${OUTPUT_FILE}"
COMMAND="magick ${INPUT_FILE} -bordercolor ${ARGS_BORDERCOLOR} -border ${ARGS_BORDER} ${OUTPUT_FILE}"
decho "${COMMAND}"
eval $COMMAND
INPUT_FILE=$OUTPUT_FILE
Expand All @@ -186,31 +216,43 @@ BORDER_H=`echo "$CALC_BORDER_SIZE_H" | bc`

FONT_SIZE=
if [[ "$ARGS_FONT_SIZE" == small ]]; then
FONT_SIZE=`echo "${BORDER_H} * 0.2" | bc`
FONT_SIZE=`echo "scale=0; ${BORDER_H} * 0.2 / 1" | bc`
elif [[ "$ARGS_FONT_SIZE" == medium ]]; then
FONT_SIZE=`echo "${BORDER_H} * 0.3" | bc`
FONT_SIZE=`echo "scale=0; ${BORDER_H} * 0.3 / 1" | bc`
else
FONT_SIZE=`echo "${BORDER_H} * 0.5" | bc`
FONT_SIZE=`echo "scale=0; ${BORDER_H} * 0.5 / 1" | bc`
fi

OFFSET_H=`echo "${BORDER_H} - ${FONT_SIZE} - (${FONT_SIZE} / 10)" | bc`
# Ensure font size is at least 1 if border exists
if [ ! -z "$ARGS_BORDER" ] && [ "$FONT_SIZE" -lt 1 ]; then
FONT_SIZE=12
fi

OFFSET_H=`echo "scale=0; (${BORDER_H} - ${FONT_SIZE} - (${FONT_SIZE} / 10)) / 2 / 1" | bc`

decho "Border size ${BORDER_W} x ${BORDER_H}"
decho "OFFSET_H ${OFFSET_H}"

if [ ! -z "$ARGS_COPYRIGHT" -a ! -z "$ARGS_BORDER" ]; then
COMMAND="magick ${INPUT_FILE} -gravity SouthEast -pointsize ${FONT_SIZE} -annotate +${BORDER_W}+${OFFSET_H} \"© ${ARGS_COPYRIGHT}\" ${OUTPUT_FILE}"
decho "${COMMAND}"
eval $COMMAND
INPUT_FILE=$OUTPUT_FILE
fi

if [ ! -z "$ARGS_CUSTOM_TEXT" -a ! -z "$ARGS_BORDER" ]; then
COMMAND="convert ${INPUT_FILE} -gravity southwest -pointsize ${FONT_SIZE} -annotate +${BORDER_W}+${OFFSET_H} \"${ARGS_CUSTOM_TEXT}\" ${OUTPUT_FILE}"
COMMAND="magick ${INPUT_FILE} -gravity North -pointsize ${FONT_SIZE} -annotate +${BORDER_W}+${OFFSET_H} \"${ARGS_CUSTOM_TEXT}\" ${OUTPUT_FILE}"
decho "${COMMAND}"
eval $COMMAND
INPUT_FILE=$OUTPUT_FILE
fi

if [ ! -z "$ARGS_ANNOTATION_TEXT" -a ! -z "$ARGS_BORDER" ]; then
COMMAND="convert ${INPUT_FILE} -gravity Southeast -pointsize ${FONT_SIZE} -annotate +${BORDER_W}+${OFFSET_H} \"${ARGS_ANNOTATION_TEXT}\" ${OUTPUT_FILE}"
COMMAND="magick ${INPUT_FILE} -gravity SouthWest -pointsize ${FONT_SIZE} -annotate +${BORDER_W}+${OFFSET_H} \"${ARGS_ANNOTATION_TEXT}\" ${OUTPUT_FILE}"
decho "${COMMAND}"
eval $COMMAND
fi

if [ ! -z "$ARGS_STRIP_EXIF" ]; then
eval "exiftool -all= ${OUTPUT_FILE}"
fi

Binary file removed photo_output.jpg
Binary file not shown.
33 changes: 19 additions & 14 deletions run_for_all.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#!/bin/bash

# Check if the pattern and suffix arguments are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 'pattern' 'suffix'"
echo "Example: $0 '*.jpg' '_bor'"
exit 1
if [ -z "$1" ]; then
echo " > Setting default value for 'pattern' to './photos/*.JPG'"
pattern="./photos/*.JPG"
else
pattern="$1"
fi

# Define the pattern from the first argument
pattern="$1"

# Define the suffix from the second argument
suffix="$2"
if [ -z "$2" ]; then
echo " > Setting default value for 'suffix' to '_bor'"
suffix="_bor"
else
suffix="$2"
fi

# Loop through each file matching the pattern
for input_file in $pattern; do
# Check if the file exists to avoid processing a non-matching pattern
if [ ! -f "$input_file" ]; then
echo "No files found matching the pattern: $pattern"
echo " > No files found matching the pattern: $pattern"
exit 1
fi

echo "Converting $input_file"
echo " > Converting $input_file"

# Extract the directory path of the input file
dir_path=$(dirname "$input_file")
Expand All @@ -35,6 +36,10 @@ for input_file in $pattern; do
# Define the output file name by appending the suffix to the base name and adding the extension
output_file="${dir_path}/${base_name}${suffix}.${extension}"

./bor.sh -b 5%x10% -e cameramodel,focallength35,fnumber,exptime,isospeed,stripexif $input_file $output_file
echo "Output $output_file"
datetime=$(TZ=Europe/Amsterdam date +"%d %B %Y")
# -t "$datetime"

./bor.sh -r 1280X1920 -b 3%x4% -e cameramodel,focallength,fnumber,exptime,isospeed -f large -c "Wim de Haan" $input_file $output_file
#./bor.sh -r 1280X1920 -b 4%x3% -e cameramodel,focallength,fnumber,exptime,isospeed -f large -c "Wim de Haan" $input_file $output_file
echo " > Output $output_file"
done
File renamed without changes
Binary file added sample_bor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.