Daniel Doubrovkine bio photo

Daniel Doubrovkine

aka dB., @awscloud, former CTO @artsy, +@vestris, NYC

Email Twitter LinkedIn Github Strava
Creative Commons License

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.

pixmatch-sample

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’re 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.