Skip to content

Instantly share code, notes, and snippets.

@kyohei-shimada
Created May 20, 2015 16:27
Show Gist options
  • Save kyohei-shimada/8b7c109d015a497fe54f to your computer and use it in GitHub Desktop.
Save kyohei-shimada/8b7c109d015a497fe54f to your computer and use it in GitHub Desktop.
2つの画像のxorをとるテスト
require 'chunky_png'
# 画像サイズと色の種類は同じと仮定
image1 = ChunkyPNG::Image.from_file('sample1.png')
image2 = ChunkyPNG::Image.from_file('sample2.png')
xor_image = ChunkyPNG::Image.new(image1.width, image1.height, ChunkyPNG::Color::TRANSPARENT)
image1.height.times do |h|
image2.width.times do |w|
# 0xff透過色を無視
xor_image[w, h] = image1[w, h] ^ image2[w, h] | 0xff
end
end
xor_image.save('xor_image.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment