Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use glitch.sh to create a glitch image #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 0 additions & 2 deletions bash/after_gifsy_and_glitch.sh

This file was deleted.

99 changes: 81 additions & 18 deletions bash/glitch.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,85 @@
newFileName='glitch_'$1;
cat "$1" > "$newFileName";

function i__gli() {
fileSize=$(wc -c < "$1");
headerSize=1000;
skip=$(shuf -i "$headerSize"-"$fileSize" -n 1);
count=$(shuf -i 1-10 -n 1);
for i in $(seq 1 $count);do byteStr=$byteStr'\x'$(shuf -i 0-254 -n 1); done;
echo $byteStr' @ '$skip;
printf $byteStr | dd of="$newFileName" bs=1 seek=$skip count=$count conv=notrunc
#!/bin/sh

clear

settings(){
# Get the original image
image=$1

# Get image name
name=${image%.*}

# Get the number for the random
number=$2

# Check if $number is an integer
# throw an error if it's not
if ! [[ "$number" =~ ^[0-9]+$ ]]; then
error "!@"
else
glitch "!@"
fi
}

steps=$(shuf -i 1-$2 -n 1);
for i in $(seq 1 $steps);
do
byteStr='';
i__gli "$1";
done

glitch(){
# I'm not sure why i__gli()
# doesn't work with png images
# (and that's really strange
# because it is the same code
# gifsy.sh uses) so if $image
# is a png file it makes a
# copy in jpg format

# Get the image extension
extension="${image##*.}"

if [ $extension == "png" ]; then
convert "$image" "${name}.jpg"
image=${name}.jpg
fi

# Name of the new image
new_image=glitch_$image


# Make a copy of the original image
cat "$image" > "$new_image"

# I'm not really sure what's happening here
function i__gli() {
fileSize=$(wc -c < "$1");
headerSize=1000
skip=$(shuf -i "$headerSize"-"$fileSize" -n 1)
count=$(shuf -i 1-10 -n 1)

for i in $(seq 1 $count)
do
byteStr=$byteStr'\x'$(shuf -i 0-254 -n 1)
done

echo $byteStr' @ '$skip
printf $byteStr | dd of="$new_image" bs=1 seek=$skip count=$count conv=notrunc
}

# Same as before but stronger
steps=$(shuf -i 1-$number -n 1);
for i in $(seq 1 $steps);
do
byteStr='';
i__gli "$image"
done

# Delete the jpg copy file if it was created
if [ $extension == "png" ]; then
rm $image
fi

exit 0
}

error(){
echo "Something went wrong."
exit 1
}

settings "$@"