Created
April 1, 2010 02:15
-
-
Save mickey24/351230 to your computer and use it in GitHub Desktop.
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 | |
# twit_anime_icon.rb | |
# convert an animated gif file to an uploadable format for Twitter. | |
infile = ARGV[0] || "" | |
outfile = ARGV[1] || "output.gif" | |
if infile.empty? | |
puts "usage: #{$0} input.gif [output.gif]" | |
exit 1 | |
elsif !File.file?(infile) | |
puts "#{infile}: file not found" | |
exit 1 | |
elsif File.exist?(outfile) | |
puts "#{outfile}: file exists" | |
exit 1 | |
end | |
size = File.size(infile) | |
open(infile, "rb") {|fi| | |
data = fi.read(size - 1) | |
if fi.read != 0x3b.chr | |
puts "#{infile}: invalid input file" | |
exit 1 | |
end | |
open(outfile, "wb") {|fo| | |
fo.write data | |
fo.write 0x3c.chr | |
fo.write 0x2c.chr | |
} | |
puts "success" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment