Ok, after looking into this some more, it turned out to be a very silly mistake. My ImageMagick installation wasn't being found by my script. Adding the path solved the problem, and I was able to simplify everything a bit. This one works from the Finder Services and does exactly what I want. I was helped by this answer: https://apple.stackexchange.com/a/119109/288589

[![Working solution][1]][1]


  [1]: https://i.sstatic.net/K19ri.png