listen, when you run imageMagick from the command line you use a 'string' to pass that into the shell. And you need to 'delimit' the string.
this gets complicated when you start using snippits of code to build your script. if some of it is in bash of shell script, it has to be delimited differently inside the script.
you might try back slashing the '%'.
if a person gives you an untested snippet like this person did to you, you are better off ignoring their input. He didn't even test it. how hard could that be?
he didn't even put in a part that tells you, if yo uuse it wrongly, how to use the script.
he's trying to waste your time OR he's too inexperienced to help you.
learning to master ImageMagick is very very hard.
there are pages that 'give away' examples and I suggest finding those pages. Let me see?
you can load them local (which I suggest) but you need to know which file it is.
let me find you a proper help page (hundreds of examples).
and remember 'cut and paste' of snippits doesn't work the same as when they are in a script because the delimiting of important characters, such as for '-' or '%' work differently inside a script.
https://imagemagick.org/script/convert.php
you can load these help scripts local, I believe, too. It's always good to start with a working examples.
I wrote scripts that broke if I added an exclaimation point to the input text.
if you need a '"' inside the script you have to delimit it in a very not-trivial way.