Skip to content

Commit

Permalink
add support for 'folder' action (to use for watermarking a whole folder)
Browse files Browse the repository at this point in the history
  • Loading branch information
pforret committed Apr 14, 2023
1 parent 46aa5b8 commit ee3e173
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ log/*
.DS_Store
/playground/
/tests/
/temp/
48 changes: 39 additions & 9 deletions splashmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ option|u|url|photo URL override (empty: use URL from API)|
option|P|PIXABAY_ACCESSKEY|Pixabay access key|
option|U|UNSPLASH_ACCESSKEY|Unsplash access key|
option|R|REPLICATE_ACCESSKEY|Replicate API key|
choice|1|action|action to perform|unsplash,pixabay,text2image,file,url,sizes,check,env,update
option|X|EXPORT|export to subfolder|export
option|E|EXTENSION|image extension to use|jpg
choice|1|action|action to perform|unsplash,pixabay,text2image,file,folder,url,sizes,check,env,update
param|?|input|URL or search term
param|?|output|output file
" -v -e '^#' -e '^\s*$'
Expand Down Expand Up @@ -70,13 +72,13 @@ unsplash)
### Unsplash URL: download one photo
photo_id=$(basename "$input")
# shellcheck disable=SC2154
[[ -z "${output:-}" ]] && output="unsplash.$photo_id.jpg"
[[ -z "${output:-}" ]] && output="unsplash.$photo_id.$EXTENSION"
else
### search for terms
photo_id=$(unsplash:search "$input")
local photo_slug
photo_slug=$(Str:slugify "$input")
[[ -z "${output:-}" ]] && output="unsplash.$photo_slug.jpg"
[[ -z "${output:-}" ]] && output="unsplash.$photo_slug.$EXTENSION"
fi
IO:debug "Output file: [$output]"
if [[ -n "$photo_id" ]]; then
Expand All @@ -100,7 +102,7 @@ text2image)
### search for terms
local prompt_hash temp_image
prompt_hash=$(<<< "$input" Str:digest 12)
[[ -z "${output:-}" ]] && output="$image_source.$prompt_hash.jpg"
[[ -z "${output:-}" ]] && output="$image_source.$prompt_hash.$EXTENSION"
temp_image="$tmp_dir/$image_source.$prompt_hash.png"
IO:debug "Output file: [$output]"
image_file=$(ai:text2image "$input" "$temp_image")
Expand All @@ -125,12 +127,12 @@ pixabay)
### Unsplash URL: download one photo
photo_id=$(basename "${input//-//}")
# shellcheck disable=SC2154
[[ -z "${output:-}" ]] && output="pixabay.$photo_id.jpg"
[[ -z "${output:-}" ]] && output="pixabay.$photo_id.$EXTENSION"
else
### search for terms
photo_id=$(pixabay:search "$input")
photo_slug=$(Str:slugify "$input")
[[ -z "${output:-}" ]] && output="pixabay.$photo_slug.jpg"
[[ -z "${output:-}" ]] && output="pixabay.$photo_slug.$EXTENSION"
fi
IO:debug "Output file: [$output]"
if [[ -n "$photo_id" ]]; then
Expand All @@ -142,7 +144,7 @@ pixabay)
fi
;;

file | f)
file)
#TIP: use «splashmark file» to add texts and effects to a existing image
#TIP:> splashmark file waterfall.jpg sources/original.jpg
#TIP:> splashmark --title "Strawberry" -w 1280 -c 640 -e dark,median,grain file sources/original.jpg waterfall.jpg
Expand All @@ -153,12 +155,40 @@ file | f)
local hash
name=$(basename "$input" .jpg | cut -c1-8)
hash=$(<<< "$input" Str:digest 6)
[[ -z "${output:-}" ]] && output="file.$name.$hash.jpg"
[[ -z "${output:-}" ]] && output="file.$name.$hash.$EXTENSION"
IO:debug "Output file: [$output]"
Img:modify "$input" "$output"
IO:print "$output"
;;

folder)
#TIP: use «splashmark folder» to add texts and effects to a existing image
#TIP:> splashmark folder /home/folder
#TIP:> splashmark --title "Strawberry" -w 1280 -c 640 -e dark,median,grain file sources/original.jpg waterfall.jpg
image_source="file"
[[ ! -d "$input" ]] && IO:die "Cannot find input folder [$input]"
IO:debug "Input folder : [$input]"
local output_folder
output_folder="$(realpath "$input")/$EXPORT"
[[ ! -d "$output_folder" ]] && mkdir -p "$output_folder"
IO:debug "Output folder : [$output_folder]"
local file base export_file
find "$input" -maxdepth 1 -type f -name "*.jpg" \
| while read -r file ; do
base=$(basename "$file" .jpg)
export_file="$output_folder/$base.$EXTENSION"
Img:modify "$file" "$export_file"
IO:print "$export_file"
done
find "$input" -maxdepth 1 -type f -name "*.png" \
| while read -r file ; do
base=$(basename "$file" .png)
export_file="$output_folder/$base.$EXTENSION"
Img:modify "$file" "$export_file"
IO:print "$export_file"
done
;;

url | u)
#TIP: use «splashmark url» to add texts and effects to a image that will be downloaded from a URL
#TIP:> splashmark file waterfall.jpg "https://i.imgur.com/rbXZcVH.jpg"
Expand All @@ -169,7 +199,7 @@ url | u)
[[ ! -f "$image_file" ]] && IO:die "Cannot download input image [$input]"
name=$(basename "$image_file" .jpg | cut -c1-8)
hash=$(<<< "$input" Str:digest 6)
[[ -z "${output:-}" ]] && output="url.$name.$hash.jpg"
[[ -z "${output:-}" ]] && output="url.$name.$hash.$EXTENSION"
IO:debug "Process cached image [$image_file] -> [$output]"
Img:modify "$image_file" "$output"
IO:print "$output"
Expand Down
6 changes: 6 additions & 0 deletions watermark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

[[ ! $(command -v splashmark) ]] && echo "Requires pforret/splashmark" && exit 1
year=$(date +%Y)
name="Peter Forret"
splashmark -3 "$year $name" folder "$PWD"

0 comments on commit ee3e173

Please sign in to comment.