Page 1 of 1

Adding background gradient to each image, then convert to pdf

Posted: 2019-03-27T03:51:50-07:00
by keljnr
I currently have a script that when you right click on a folder to execute a batch file, converts all the EXRs to PDF:

cd %~dpnx1
for %%a in (.) do set currentfolder=%%~na
start cmd /k convert *exr* -colorspace RGB -colorspace sRGB -background none -alpha remove "%currentfolder%.pdf"


However, I'm wanting to add a gradient background to each of the exrs before they are sent to the PDF...

Is this possible? Hope someone can help.
Thanks.

Re: Adding background gradient to each image, then convert to pdf

Posted: 2019-03-27T06:38:50-07:00
by snibgo
I think you want to flatten each input over a gradient. Is that correct?

What gradient do you want? I will assume you want black at top-left and white at bottom-right.

What version IM do you use? You use "convert" which implies v6. I suggest you use v7 and "magick".

You can do this by cloning the input, use "-sparse-color" to change that to a gradient, then flatten the input over the clone. This is fairly simple when you have just one input.

But your command reads all the exr files and processes them together, so the command is messier:

Code: Select all

magick *exr* null: ( -clone 0--2 -sparse-color bilinear 0,0,black,%[fx:w-1],%[fx:h-1],white ) -compose DstOver -layers Composite "%currentfolder%.pdf"
I have removed "-colorspace RGB -colorspace sRGB" because it seems pointless. This is Windows CMD format. For Windows BAT, double each % to %%.

Re: Adding background gradient to each image, then convert to pdf

Posted: 2019-03-27T07:41:46-07:00
by keljnr
Many thanks for getting back to me. I'm actually using v7 of imagemagick.
Upon running the script, I get the following error:

Code: Select all

magick: invalid argument for option 'sparse-color': Color found, instead of X-co
ord @ error/operation.c/SparseColorOption/272.

Re: Adding background gradient to each image, then convert to pdf

Posted: 2019-03-27T07:54:31-07:00
by snibgo
Are you running it in a BAT file? If so, did you double each % to %%?

Re: Adding background gradient to each image, then convert to pdf

Posted: 2019-03-27T08:42:17-07:00
by keljnr
No I hadn't, works perfectly. Great job snibgo!! :-)