Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created April 18, 2010 08:36
Show Gist options
  • Save hitode909/370110 to your computer and use it in GitHub Desktop.
Save hitode909/370110 to your computer and use it in GitHub Desktop.
画像の色を反転させるプロキシ
#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
require 'RMagick'
handler = Proc.new() { |req,res|
if res['content-type'] =~ /image/
begin
img = Magick::Image.from_blob(res.body).first
body = img.negate.to_blob
res.body = body
rescue
end
end
}
s = WEBrick::HTTPProxyServer.new(
:BindAddress => '127.0.0.1',
:Port => 9090,
:ProxyContentHandler => handler
)
Signal.trap('INT') do
s.shutdown
end
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment