I had a nice time today wrapping up the Idee PixMatch API in a Ruby gem. PixMatch is a general image matching engine that allows you to perform large scale image comparisons and I wanted to upload a few million images and check it out.
The resulting gem is here, MIT licensed. I copied the file structure from skittles which copied it from twitter. Open-source neatly promotes copy-paste these days – we at artsy call it collage!
There are two kinds of requests in PixMatch: simple REST GETs and POSTs and multipart posts with image data. I ended up not using the RESTful request wrappers that exist in both and instead switched to rest-client, a much simpler and more powerful framework. To upload images we need to be posting a multipart payload where file names are images[0], images[1], etc. I remember it taking me a week to write multipart client support in C++ ten years ago. Today it’s a no-brainer made possible by rest-client.
def add(files)
files_hash = { }
payload = files.each { |f| files_hash["images[#{files_hash.size}]"] = f.is_a?(File) ? f : File.new(f, "rb") }
RestClient::Request.new({ method: :post, url: "https://api.tineye.com/rest&method=add", payload: payload }).execute
end
Now calling add on a bunch of files is pretty.
PixMatch.add(Dir.glob("images/\*.jpg"))
PixMatch is not available publicly, e-mail info[at]ideeinc.com to get started.