Skip to content

Instantly share code, notes, and snippets.

@tobynet
Forked from hitode909/negaproxy.rb
Created June 12, 2011 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tobynet/1021602 to your computer and use it in GitHub Desktop.
Save tobynet/1021602 to your computer and use it in GitHub Desktop.
モザイク化プロキシ
#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
require 'RMagick'
pixelize_rate = 8.0
handler = Proc.new() { |req,res|
if (res['content-type'] =~ /png/)
begin
res.body = Magick::Image.from_blob(res.body).first.scale(1.0 / pixelize_rate).scale(pixelize_rate).to_blob
res.content_length = res.body.size
res['cache-control'] = 'no-cache'
rescue => e
p e
end
end
}
s = WEBrick::HTTPProxyServer.new(
:BindAddress => '127.0.0.1',
:Port => 5462,
:ProxyContentHandler => handler
)
Signal.trap('INT') do
s.shutdown
end
s.start
@tobynet
Copy link
Author

tobynet commented Jun 12, 2011

アルファチャンネル付きの透過pngをそのまま加工すると色おかしくなるっぽい
http://d.hatena.ne.jp/shokai/20100212/1265961828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment