How to pick a color from an image's corner and use it...

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
Atze

How to pick a color from an image's corner and use it...

Post by Atze »

Hi.

I have another commandline-problem where I can't get rid of:

How to pick a color from an image's corner and use it as the background-color.

There seems to exist an api for that ("getImagePixelColor(1, 1)") but I would need it in commandline.

Regards,
Atze
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to pick a color from an image's corner and use it...

Post by Bonzo »

There may be something useful here:
http://redux.imagemagick.org/discourse- ... rner+pixel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to pick a color from an image's corner and use it...

Post by fmw42 »

This makes a 100x100 background color image from the color at coordinates at 20,20 of someimage.jpg


coords="20,20"
color=`convert someimage.jpg -format "%[pixel:s.p{$coords}]" info:`
convert -size 100x100 xc:"$color" background.jpg


see fx escapes

http://www.imagemagick.org/Usage/transform/#fx_escapes
Atze

Re: How to pick a color from an image's corner and use it...

Post by Atze »

@fmw42:
Ok, thanks for info. I will take a deeper look.

@Bonzo:
Thanks for the link. I wonder that I didn't find it yet.
This looks really interesting:
convert logo: -transparent $(echo `convert logo: -format "%[pixel:p{0,0}]" info:`) logo_tmp.png
I'm not sure, if I really understand this syntax. It seems to be a Unix-shell syntax, right?
Looks quite complecated. I'm Windows only user, sorry that I didn't mention it yet.
Could someone help me 'translate' it to DOS-batch syntax?

Regards,
Atze
Atze

Re: How to pick a color from an image's corner and use it...

Post by Atze »

Finaly I got it convrted to DOS-syntax:
FOR /F "delims=" %%A IN ('convert.exe input.jpg -format "%%[pixel:s.p{0,0}]" info:') DO SET BACKCOLOR=%%A
Thanks for help!

Atze
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to pick a color from an image's corner and use it...

Post by anthony »

fmw42 wrote:This makes a 100x100 background color image from the color at coordinates at 20,20 of someimage.jpg
Here is an alternative from the 'Canvas Creation' page of IM examples...
http://www.imagemagick.org/Usage/canvas/#solid

Code: Select all

convert someimage.jpg  -crop 1x1+20+20 +repage -scale 100x100\!  background.png
WARNING: JPG is lossy, colors may not be exact!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to pick a color from an image's corner and use it...

Post by fmw42 »

anthony wrote:
fmw42 wrote:This makes a 100x100 background color image from the color at coordinates at 20,20 of someimage.jpg
Here is an alternative from the 'Canvas Creation' page of IM examples...
http://www.imagemagick.org/Usage/canvas/#solid

Code: Select all

convert someimage.jpg  -crop 1x1+20+20 +repage -scale 100x100\!  background.png
WARNING: JPG is lossy, colors may not be exact!

Yes, Anthony's method is more elegant and simpler.
Post Reply