Code: Select all
img.excerpt!(x, y, width, height)
img.write(f)
new_img = Magick::Image.read(f).first
img.signature != new_img.signature # why?
Code: Select all
img.excerpt!(x, y, width, height)
img.write(f)
new_img = Magick::Image.read(f).first
img.signature != new_img.signature # why?
Code: Select all
img.excerpt!(x, y, width, height)
puts img.inspect
img.write(f)
new_img = Magick::Image.read(f).first
puts new_img.inspect
img.signature != new_img.signature # why?
Code: Select all
require 'rubygems'
require 'rmagick'
puts "processing file %s"%[file = ARGV.shift]
puts " and you've choosen %sto process thresholds"%[(process = /process/i =~ ARGV.shift ) ? "" : "NOT "]
img = Magick::ImageList.new.read(file).first
img = img.black_threshold(200).white_threshold(20) if process
bb = img.bounding_box
excerpt = img.excerpt(bb.x, bb.y, bb.width, bb.height)
signature = excerpt.signature
# saving to a file and reading back
f = "excerpt-" + file
img.write(f)
new_img = Magick::Image.read(f).first
puts " RESULT: img.signature %s new_img.signature"%( img.signature == new_img.signature ? "==" : "!=" )
Code: Select all
ruby test_signature.rb test_signature.tif
Code: Select all
ruby test_signature.rb test_signature.tif process
Code: Select all
convert -verbose signature_test.tif -black-threshold 200 -white-threshold 20 signature_test2.tif
Code: Select all
identify signature_test2.tif
Code: Select all
>ruby signature_test.rb signature_test.tif
processing file signature_test.tif
and you've choosen NOT to process thresholds
RESULT: img.signature == new_img.signature
>ruby signature_test.rb signature_test.tif process
processing file signature_test.tif
and you've choosen to process thresholds
RESULT: img.signature != new_img.signature
Code: Select all
>ruby signature_test.rb signature_test.tif process
processing file signature_test.tif
and you've choosen to process thresholds
RESULT: img.signature != new_img.signature
img.signature = e9bc545d337ad96e7a149528e37bc5a2383fb9d2ac030dfac6ee96be4baa70ba
new_img.signature = 1fd61a6b86710183cd38f6e979963a9dd319862dfb542aac890db04f38d742b3
Code: Select all
>identify -quiet -format "%#" signature_test.tif
134dce294ff4e02507af8a986e1040417df6bb7cb722ea292b6d6d0a17bc653f
Code: Select all
convert signature_test.tif -black-threshold 78% -format "%#" -write info:- signature_test2.tif
Code: Select all
identify -format "%#" signature_test2.tif
Code: Select all
convert signature_test.tif -black-threshold 78% -type TrueColor -depth 8 -format "%#" -write info:- signature_test2.tif
Code: Select all
identify -format "%#" signature_test2.tif
ImageMagick has a flag known as 'taint' which becomes true is some pixels or meta-data was modified.bon-bon wrote:The result depends on wheter the image was processed or no. Why?
Code: Select all
require 'rubygems'
require 'rmagick'
puts "processing file %s"%[file = ARGV.shift]
puts " and you've choosen %sto process thresholds"%[(process = /process/i =~ ARGV.shift ) ? "" : "NOT "]
img = Magick::ImageList.new.read(file).first
img = img.black_threshold(200).white_threshold(20) if process
img.image_type = Magick::TrueColorType
# saving to a file and reading back
f = "excerpt-" + file
img.write(f)
new_img = Magick::Image.read(f).first
puts " RESULT: img.signature %s new_img.signature"%( img.signature == new_img.signature ? "==" : "!=" )
puts " img.signature = %s"%img.signature
puts " new_img.signature = %s"%new_img.signature
Code: Select all
>ruby signature_test.rb signature_test.tif process
processing file signature_test.tif
and you've choosen to process thresholds
RESULT: img.signature == new_img.signature
img.signature = e9bc545d337ad96e7a149528e37bc5a2383fb9d2ac030dfac6ee96be4baa70ba
new_img.signature = e9bc545d337ad96e7a149528e37bc5a2383fb9d2ac030dfac6ee96be4baa70ba
>ruby signature_test.rb signature_test.tif
processing file signature_test.tif
and you've choosen NOT to process thresholds
RESULT: img.signature == new_img.signature
img.signature = 134dce294ff4e02507af8a986e1040417df6bb7cb722ea292b6d6d0a17bc653f
new_img.signature = 134dce294ff4e02507af8a986e1040417df6bb7cb722ea292b6d6d0a17bc653f