1

I have a zsh script. There is a function ...

imgPrep()
{
local inFilePath=$1
local outFilePath=$2
local cropHeight=$3
local resize=$4
shift; shift; shift; shift
local options=$@

convert ${inFilePath} -crop 0x${cropHeight}+0+0 +repage -resize ${resize}% ${options} ${outFilePath}
}

I call the function like so:

IMoptions="-despeckle -unsharp 0x3+1+0"
imgPrep ${inputImgFilePath} ${headerImgFilePath} ${headerHeight} ${scale} ${IMoptions}

convert command fails , presumably because single quotes should not be there.

convert somefile.jpg -crop 0x60+0+0 +repage -resize 410% '-despeckle -unsharp 0x3+1+0' output.tif

convert: unrecognized option `-despeckle -unsharp 0x3+1+0' @ error/convert.c/ConvertImageCommand/1437

How do I fix this please?

1 Answers1

0

I resolved the issue by using an array

local options=("$@") # Store options in an array

convert ${inFilePath} -crop 0x${cropHeight}+0+0 +repage -resize ${resize}% "${options[@]}" ${outFilePath}

...

imgPrep ${inputImgFilePath} ${headerImgFilePath} ${headerHeight} ${scale} "${IMoptions[@]}"

Thank you Daniel Kelley for providing the correct answer. Luckily, I caught it before it was deleted, which is a shame.

  • You don't really need an array; you can just use `"$@"` directly instead of trying to assign it to a new name in the first place. `imgPrep ... "$@" ${outFilepath}`. – chepner Mar 17 '23 at 16:50
  • @chepner good to know. You should have made it an answer instead of a comment. – timelessbeing Mar 18 '23 at 03:59