class Pixmap
  PIXMAP_FORMATS = [, ]   
  PIXMAP_BINARY_FORMATS = []  

  def write_ppm(ios, format=)
    if not PIXMAP_FORMATS.include?(format)
      raise NotImplementedError,  
    end
    ios.puts format, , 
    ios.binmode if PIXMAP_BINARY_FORMATS.include?(format)
    @height.times do |y|
      @width.times do |x|
        case format
        when  then ios.print @data[x][y].values.join(),
        when  then ios.print @data[x][y].values.pack('C3')
        end
      end
    end
  end

  def save(filename, opts={:format=>})
    File.open(filename, 'w') do |f|
      write_ppm(f, opts[:format])
    end
  end

  def print(opts={:format=>})
    write_ppm($stdout, opts[:format])
  end

  def save_as_jpeg(filename, quality=75)
    pipe = IO.popen(, 'w')
    write_ppm(pipe)
    pipe.close
  end
end

image = Pixmap.open('file.ppm')
image.save_as_jpeg('file.jpg')