Skip to content

Instantly share code, notes, and snippets.



Created Aug 12, 2013
What would you like to do?
Simple script to rin perfectly good image files.
#!/usr/bin/env ruby
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.
if ARGV.size < 3
puts "Usage: #{__FILE__} source-image byte-mod-int bitmask-int"
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, 'rb') do |f|, "w+b") do |ff|
f.each_byte do |b|
b_counter += 1
b_counter %= byte_mod
if b_counter == 0
b = b && bitmask
# The trick here is that 'print'
# works with strings and will bork your
# data in the wrong way, hence `chr`
ff.print b.chr
Copyright (c) 2013 James Britt / Neurogami
Released under the The MIT License -
Feed your head
Hack your world
Live curious
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.