summaryrefslogtreecommitdiffstats
path: root/.local/bin/hide
blob: 1dc473d1e9de6f3d6cf32811f42cdbb6cb05568d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

#Description:
#This hides an image within an image as an overlay. Useful for watermarking images.

#1 is foreground
#2 is background
#3 is output
#gemsize is an env var for dictating how big or small the overlayed photo should be
#TMPDIR is an env var for dictating where temporary files for this program should be stored

#Axioms:

#Dependencies: https://packages.debian.org/sid/imagemagick


if [ "$TMPDIR" = "" ]
then
    TMPDIR=/tmp
fi


rotation=$(echo "$RANDOM%360"|bc)
#widthforeground=$(identify -format "%[fx:w]" "/home/$USER/Pictures/wojak/soy/5486*")
#heightforeground=$(identify -format "%[fx:h]" "/home/$USER/Pictures/wojak/soy/5486*")
widthbackground=$(identify -format "%[fx:w]" "$1")
heightbackground=$(identify -format "%[fx:h]" "$1")


if [ "$gemsize" = "" ]
then
    foregroundresizefactor=$(echo "$heightbackground*0.15"|bc)x
else
    foregroundresizefactor=$(echo "$heightbackground*$gemsize"|bc)x
fi

foregroundLegalMovingDistanceWidth=$(echo "$widthbackground/2"|bc)
foregroundLegalMovingDistanceHeight=$(echo "$heightbackground/2"|bc)

foregroundActualMovingDistanceWidth=$(echo "$RANDOM%$foregroundLegalMovingDistanceWidth"|bc)
foregroundActualMovingDistanceHeight=$(echo "$RANDOM%$foregroundLegalMovingDistanceHeight"|bc)

if [[ $(echo "$RANDOM%2"|bc) == 0 ]]
then
    foregroundActualMovingDistanceWidth=-$foregroundActualMovingDistanceWidth
fi

if [[ $(echo "$RANDOM%2"|bc) == 0 ]]
then
    foregroundActualMovingDistanceHeight=-$foregroundActualMovingDistanceHeight
fi

convert "$2" -alpha set -background none -colorspace RGB -trim -rotate "$rotation" -fuzz 10% -transparent White -resize "$foregroundresizefactor" -trim "$TMPDIR/trans.png"
composite -dissolve 70% -gravity center -geometry +"$foregroundActualMovingDistanceWidth"+"$foregroundActualMovingDistanceHeight" "$TMPDIR/trans.png" "$1" "$3"
rm "$TMPDIR/trans.png"

echo "$(identify -ping -format '%[width]' "$3")*0.5"|bc
echo "$(identify -ping -format '%[height]' "$3")*0.5"|bc

finalwidth=$(echo "$(identify -ping -format '%[width]' "$3")*0.5"|bc)
finalheight=$(echo "$(identify -ping -format '%[height]' "$3")*0.5"|bc)
xlocation=$(echo "$finalwidth-$foregroundActualMovingDistanceWidth"|bc)
ylocation=$(echo "$finalheight-$foregroundActualMovingDistanceWidth"|bc)
echo "hidden gem is at ($xlocation, $ylocation)"