Adding background gradient to each image, then convert to pdf

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
keljnr
Posts: 11
Joined: 2018-10-16T03:29:47-07:00
Authentication code: 1152

Adding background gradient to each image, then convert to pdf

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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 %%.
snibgo's IM pages: im.snibgo.com
keljnr
Posts: 11
Joined: 2018-10-16T03:29:47-07:00
Authentication code: 1152

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Are you running it in a BAT file? If so, did you double each % to %%?
snibgo's IM pages: im.snibgo.com
keljnr
Posts: 11
Joined: 2018-10-16T03:29:47-07:00
Authentication code: 1152

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

Post by keljnr »

No I hadn't, works perfectly. Great job snibgo!! :-)
Post Reply