Skip to content

Instantly share code, notes, and snippets.

@ssig33
Forked from hitode909/negaproxy.rb
Created February 1, 2012 06:46
Show Gist options
  • Save ssig33/1715541 to your computer and use it in GitHub Desktop.
Save ssig33/1715541 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