-
Notifications
You must be signed in to change notification settings - Fork 0
/
gallery.sh
executable file
·52 lines (36 loc) · 1.23 KB
/
gallery.sh
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
#!/bin/bash
# Glitch gallery automatization for extreme lazyness
# Creates 256 random glitches of a jpg image
# Arguments: INPUT_FILE
glitch(){
# Endless loop, exits if the glitched image is not corrupted
while true
do
# Glitch parameters randomization
VALUE="$((RANDOM&15))"
REPLACE="$((RANDOM&15))"
OCURR="$((RANDOM%15+1))" # Ocurrence cannot be zero
# Decimal to hexadecimal convertion for sed processing of the plain dump
HEX_VALUE=$(printf "%x" "$VALUE")
HEX_REPLACE=$(printf "%x" "$REPLACE")
# Output file name format
OFILE="${1}/${2}_${HEX_VALUE}${HEX_REPLACE}_${OCURR}.jpg"
# PERFORM THE GLITCH WITH THE ACTUAL PARAMETERS
# Plain hex dump of the input file, replace nibble, write reverse dump to output file
xxd -p $IFILE | sed s/$HEX_VALUE/$HEX_REPLACE/$OCURR | xxd -r -p > $OFILE
# If output file is valid, exit function. Else, delete file and repeat process
mogrify -format jpg $OFILE && return || rm $OFILE
done
}
# INPUT_FILE, MANDATORY PARAMETER
IFILE="$1"
# Gallery directory name format
GLITCH_PATH="${1:0:3}_gallery"
# Creates a gallery directory
mkdir $GLITCH_PATH
# Make 256 glitched images
for i in {0..255}
do
# Create a glitch image in the gallery directory
glitch $GLITCH_PATH $i
done