2

を使用して色のスペクトルを生成します。しかし、画像の幅と高さは調整可能でなければなりません。色は、HTMLカラーコード(例:#FF0000)のように16進値として使用する必要があります。は、私はそのような色スペクトルを生成したいのPython

私はスケールがどのように動作するのか知っていますが、青い赤を数え、次に赤などをカウントする方法は、画像の必要な幅を取得する解像度であると思います。画像を生成するための

私はPILについて考えた:

from PIL import Image 

im = Image.new("RGB", (width, height)) 
im.putdata(DEC_tuples) 
im.save("Picture", "PNG") 

は、既存の作業ソリューションがありますか

答えて

0

自分で解決策を見つけてもうまくいくので、生成された画像は浮動小数点数を生成しないため、新しい幅になります。

from PIL import Image 

width = 300 # Expected Width of generated Image 
height = 100 # Height of generated Image 

specratio = 255*6/width 

print ("SpecRatio: " + str(specratio)) 

red = 255 
green = 0 
blue = 0 

colors = [] 

step = round(specratio) 

for u in range (0, height): 
    for i in range (0, 255*6+1, step): 
     if i > 0 and i <= 255: 
      blue += step 
     elif i > 255 and i <= 255*2: 
      red -= step 
     elif i > 255*2 and i <= 255*3: 
      green += step 
     elif i > 255*3 and i <= 255*4: 
      blue -= step 
     elif i > 255*4 and i <= 255*5: 
      red += step 
     elif i > 255*5 and i <= 255*6: 
      green -= step 

     colors.append((red, green, blue)) 

newwidth = int(i/step+1) # Generated Width of Image without producing Float-Numbers 

print (str(colors)) 


im = Image.new("RGB", (newwidth, height)) 
im.putdata(colors) 
im.save("Picture", "PNG") 
関連する問題