简体   繁体   English

Python以相对于整数的颜色创建图像

[英]Python Create Image in color relative to integer

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 我需要用Python制作一个看起来像这样的图像,但垂直但只有绿色变成红色: 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%2F%2Fvis%4000 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. 其中绿色是10,红色是0。当它收到一个数字时,它将使条形颜色达到相关的点,并从此开始进行黑白。 I then need Python to save this image to a location. 然后,我需要Python将此图像保存到某个位置。

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! 谢谢!

I know nothing at all about Python, but I know a little about ImageMagick which is available here and has Python bindings. 我对Python一无所知,但对ImageMagick却一无所知。ImageMagick可在此处获得并具有Python绑定。

If you run this ImageMagick command at the command line: 如果在命令行上运行此ImageMagick命令:

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: 您将获得一个100x500像素的图像,称为full.jpg ,具有从绿色到红色的渐变,如下所示:

在此处输入图片说明

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: 您将获得一个名为crop.jpg的新图像,如下所示:

在此处输入图片说明

The 250 is the number that will control the amount that gets greyed out, so try varying that. 250是将控制变灰量的数字,因此请尝试更改该数字。 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 ... 因此,如果您提到的输入数字是1 ,则可能会用50代替250 (因为500px图像高度的1/10是50px),如果输入数是2可能用100代替250 ...

And maybe that will help - maybe it won't!!! 也许这会有所帮助-也许不会!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM