|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"math/rand/v2" |
|
|
|
|
"os" |
|
|
|
|
"path/filepath" |
|
|
|
@ -54,7 +55,47 @@ func glitchImage(inputFile string, outputFile string, shitSize int64, iterations |
|
|
|
|
_, err = destination.Write(shit) |
|
|
|
|
check(err, "failed to write shit data: %w") |
|
|
|
|
|
|
|
|
|
// fmt.Printf("Successfully wrote %d bytes of shit at offset %d in file %s\n", shitSize, offset, outputFilePath)
|
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func copyImage(inputFile string, outputFile string) error { |
|
|
|
|
// Ensure the output directory exists
|
|
|
|
|
makeOutputDir() |
|
|
|
|
|
|
|
|
|
// Prepend the "output" directory to the output file
|
|
|
|
|
outputFilePath := filepath.Join("output", outputFile) |
|
|
|
|
|
|
|
|
|
// Open the source file for reading
|
|
|
|
|
source, err := os.Open(inputFile) |
|
|
|
|
check(err, "failed to open source file: %w") |
|
|
|
|
defer source.Close() |
|
|
|
|
|
|
|
|
|
// Create a new file for writing the copy
|
|
|
|
|
destination, err := os.Create(outputFilePath) |
|
|
|
|
check(err, "failed to create output file: %w") |
|
|
|
|
defer destination.Close() |
|
|
|
|
|
|
|
|
|
// Copy the contents of the source file to the destination
|
|
|
|
|
_, err = destination.ReadFrom(source) |
|
|
|
|
check(err, "failed to copy file contents: %w") |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func generateGlitchedSequence(inputFile string, totalImages int, shitSize int64, iterations int64) { |
|
|
|
|
for i := 1; i <= totalImages; i++ { |
|
|
|
|
outputFileName := fmt.Sprintf("img_glitched_%d.jpeg", i) // Generate unique filenames
|
|
|
|
|
|
|
|
|
|
// Randomly decide whether to glitch or copy the image
|
|
|
|
|
if rand.Int32N(2) == 0 { |
|
|
|
|
// Glitched image
|
|
|
|
|
err := glitchImage(inputFile, outputFileName, shitSize, iterations) |
|
|
|
|
check(err, "failed to glitch image: %w") |
|
|
|
|
} else { |
|
|
|
|
// Normal image
|
|
|
|
|
err := copyImage(inputFile, outputFileName) |
|
|
|
|
check(err, "failed to copy normal image: %w") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|