Created
May 3, 2012 21:34
-
-
Save sandrewh/2589699 to your computer and use it in GitHub Desktop.
extract thumbnail from Paint.NET file
This file contains hidden or 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
require "base64" | |
# check for input file parameter | |
puts "ruby pdn_decode.rb infile.pdn" or exit if ( ARGV.length!=1 || File.extname(ARGV[0]).downcase!='.pdn' || !File.exist?(ARGV[0]) ) | |
# extract image type and image data | |
imageType, base64Data = IO.read(ARGV[0]).match(/<thumb (.+?)="(.+?)" \/>/)[1..2] | |
# determine new filename and check that it doesn't exist | |
newFile = ARGV[0][0..-5] + ".#{imageType}" | |
puts "#{newFile} already exists." or exit if File.exists? newFile | |
# save image data to new file | |
File.open(newFile, "w") {|f| f.write(Base64.decode64(base64Data))} | |
# open file -- os x specific | |
system `open #{newFile}` if RUBY_PLATFORM=~/darwin/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment