Created
May 20, 2015 16:27
-
-
Save kyohei-shimada/8b7c109d015a497fe54f to your computer and use it in GitHub Desktop.
2つの画像のxorをとるテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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