Created
August 12, 2013 04:56
-
-
Save Neurogami/6208325 to your computer and use it in GitHub Desktop.
Simple script to rin perfectly good image files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
=begin | |
Simple script to smack your glitch up. | |
Call this program with the name of an image file, and two numbers | |
The first number is used to determine when to mess with a byte in the | |
image file. If you pass in, say 2000, then even 2000th byte gets tweaked. | |
The second number is a bit-mask value. Keep it under 255. It's used to set some | |
bits in any tweaked byte. | |
The output file name is derived from the input file name and the two integers you give. | |
It makes it easier to see to what parameters gave what results. | |
=end | |
if ARGV.size < 3 | |
puts "Usage: #{__FILE__} source-image byte-mod-int bitmask-int" | |
exit | |
end | |
infile = ARGV.shift | |
byte_mod = ARGV.shift.to_i | |
bitmask = ARGV.shift.to_i | |
ext = File.extname infile | |
base = infile.sub /#{ext}$/, '' | |
outfile = "#{base}.#{byte_mod}-#{bitmask}#{ext}" | |
warn "Glitch #{infile} and write to #{outfile}" | |
b_counter = 0 | |
File.open(infile, 'rb') do |f| | |
File.open(outfile, "w+b") do |ff| | |
f.each_byte do |b| | |
b_counter += 1 | |
b_counter %= byte_mod | |
if b_counter == 0 | |
b = b && bitmask | |
end | |
# The trick here is that 'print' | |
# works with strings and will bork your | |
# data in the wrong way, hence `chr` | |
ff.print b.chr | |
end | |
end | |
end | |
=begin | |
Copyright (c) 2013 James Britt / Neurogami | |
Released under the The MIT License - http://opensource.org/licenses/MIT | |
Feed your head | |
Hack your world | |
Live curious | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment