Skip to content

Instantly share code, notes, and snippets.

@sandrewh
sandrewh / extract_pdn.rb
Created May 3, 2012 21:34
extract thumbnail from Paint.NET file
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}"