Question

I need to make an image, in Python, that looks like this but vertical and only green to red: http://www.google.co.uk/imgres?safe=off&espv=2&es_sm=91&biw=1280&bih=610&tbm=isch&tbnid=AuJytAtra5ARrM%3A&imgrefurl=http%3A%2F%2Fsvs.gsfc.nasa.gov%2Fgoto%3F4050&docid=cJwEIWqHngeBPM&imgurl=http%3A%2F%2Fsvs.gsfc.nasa.gov%2Fvis%2Fa000000%2Fa004000%2Fa004050%2Fcbar_scientists.png&w=1046&h=221&ei=9WMsU_TkHM-0hAfwyoDQBQ&zoom=1&ved=0CF4QhBwwAw&iact=rc&dur=194&page=1&start=0&ndsp=15

where green is 10 and red is 0. When it receives a number, it makes the bar colour up to the relevant point and b&w from there up. I then need Python to save this image to a location.

In this way, the image will represent how far away some thing is and show it in colour (green is far away - safe, red is close - danger) on the bar.

I know it's difficult to understand but how would I go about this?

Thanks!

Was it helpful?

Solution

I know nothing at all about Python, but I know a little about ImageMagick which is available here and has Python bindings.

If you run this ImageMagick command at the command line:

convert -size 100x500 gradient:#00ff00-#ff0000 full.jpg

you will get a 100x500 pixel image, called full.jpg, with a gradient from green to red that looks like this:

enter image description here

If you then run the following command:

convert full.jpg -gravity North -background gray -crop 100x250+0+0! -extent 100x500 crop.jpg

you will get a new image, called crop.jpg, that looks like this:

enter image description here

The 250 is the number that will control the amount that gets greyed out, so try varying that. So if your input number you mentioned is 1, maybe you would use 50 in place of 250 (because 1/10th of the 500px image height is 50px), if it is 2 maybe use 100 in place of 250...

And maybe that will help - maybe it won't!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top