How do I get Automator to process images using ImageMagick in a command script?
I would just do the whole thing at the command line as a shell script instead of using Automator to launch it. Put #!/bin/bash as the first line, and run it as 

myscript.sh image*.png 

where image*.png is your set of image files that you are apparently selecting in Automator?

If you need to run it on all files in a folder, that can be done too.

You can also test your script in automator using echo ${f%.*} instead of the commands themselves.