का उपयोग करके अजगर में एक छवि पर एक टेक्स्ट जोड़ना मेरे पास एक टेक्स्ट है "मैं बहुत अच्छा कर रहा हूं"। मैं इस पाठ को एक सुंदर पृष्ठभूमि पर रखना चाहता हूं जिसे मैंने उत्पन्न किया है। मैं "I am doing great"
को एक छवि "image.jpg"
पर सिस्टम में मौजूद रखना चाहता हूं। पाठ का प्रारंभिक बिंदु X, y पिक्सेल में होना चाहिए।छविमैजिक/पीआईएल
मैं निम्नलिखित स्निपेट कोशिश की, लेकिन हो रहा है त्रुटि: स्निपेट:
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
font = ImageFont.truetype("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf",40)
text = "Sample Text"
tcolor = (255,0,0)
text_pos = (100,100)
img = Image.open("certificate.png")
draw = ImageDraw.Draw(img)
draw.text(text_pos, text, fill=tcolor, font=font)
del draw
img.save("a_test.png")
त्रुटि:
Traceback (most recent call last):
File "img_man.py", line 13, in <module>
draw.text(text_pos, text, fill=tcolor, font=font)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageDraw.py", line 256, in text
ink, fill = self._getink(fill)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageDraw.py", line 145, in _getink
ink = self.palette.getcolor(ink)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImagePalette.py", line 62, in getcolor
self.palette = map(int, self.palette)
ValueError: invalid literal for int() with base 10: '\xed'
जनहित याचिका में एक बग हो रहा है: http://grokbase.com/t/python/image-sig/114k20c9re/perhaps-bug-report
वहाँ है कोई कामकाज मैं कोशिश कर सकता हूँ?
यह बताता है कि टेक्स्ट कैसे लिखना है, कैसे आकर्षित करना है। क्या आप पत्र आकर्षित करना चाहते हैं? मैं पायल का उपयोग कर टाइपोग्राफी के लिए नहीं हूँ। – user993563
मुझे डर है कि मैं वास्तव में छवि पर चित्र खींचने और छवि पर पाठ लिखने के बीच भेद को समझ नहीं पा रहा हूं। – badp
अद्यतन, कृपया संपादन भाग chk। – user993563