Page 1 of 1

Use color picker to set background color?

Posted: Thu Sep 21, 2023 11:44 am
by magnussandstrom
I have a flow that creates PDF from images and scale to a certain page size. But sometimes the proportions (aspect ratio) doesn't match the final size, which means that I get white stripes on the vertical or horisontal sides. But I would like fill the white background with a solid color that I pick from a certain part of the image (image edge).

Do you know of any way to achieve this?

Example:
color_picker.jpg
color_picker.jpg (241.57 KiB) Viewed 2101 times

Re: Use color picker to set background color?

Posted: Thu Sep 21, 2023 2:48 pm
by JimmyHartington
May I present another solution.
Do like when TV shows vertical video on a 16:9 TV.

Image

This action list scales the pdf to A4. https://d.pr/f/lMRKEb+
Copies the image to the background.
Scales the image non-proportinally to fit A4.
Blurs the image.

Re: Use color picker to set background color?

Posted: Thu Sep 21, 2023 3:12 pm
by magnussandstrom
Thanks Jimmy, this is great! I will suggest this solution instead.

Re: Use color picker to set background color?

Posted: Fri Sep 22, 2023 3:42 pm
by freddyp
You can pick a color value from a pixel with Imagemagick:

Code: Select all

magick image.png -format "%[fx:int(255*p{150,30}.r)],%[fx:int(255*p{150,30}.g)],%[fx:int(255*p{150,30}.b)]" info:
This will give you an output like:
139,165,224

p{150,30} is the pixel of which you read the value. The problem that I see is how to determine which pixel to take, or could you settle on a fixed location?

With Imagemagick you can also replace pixels of one color with pixels of another color. So it looks to me as if you can make it work this way should you decide not to follow Jimmy's suggestion which, by the way, I think is a good approach: it invalidates the need for choosing the correct pixel from which to take a color value.