Page 1 of 1
How to pick a color from an image's corner and use it...
Posted: 2009-01-19T07:32:41-07:00
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
Re: How to pick a color from an image's corner and use it...
Posted: 2009-01-19T11:35:17-07:00
by Bonzo
Re: How to pick a color from an image's corner and use it...
Posted: 2009-01-19T12:39:45-07:00
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
Re: How to pick a color from an image's corner and use it...
Posted: 2009-01-19T13:13:28-07:00
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
Re: How to pick a color from an image's corner and use it...
Posted: 2009-01-20T01:17:33-07:00
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
Re: How to pick a color from an image's corner and use it...
Posted: 2009-01-20T23:21:40-07:00
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!
Re: How to pick a color from an image's corner and use it...
Posted: 2009-01-21T11:31:40-07:00
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.