Getting URL image #6960
Answered
by
radarhere
mtm-aunglinnnaing
asked this question in
Q&A
Getting URL image
#6960
-
Can I get image URL after writing text to image(image url)? Please .. |
Beta Was this translation helpful? Give feedback.
Answered by
radarhere
Feb 21, 2023
Replies: 1 comment 1 reply
-
Hi. I don't understand your question.
import base64
with open("im.png", "rb") as fp:
data = base64.b64encode(fp.read())
print(b"background-image: url(data:image/gif;base64,"+data+b")") You mentioned that you wanted to write on the image first though. import base64
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
im = Image.new("RGB", (290, 65))
font = ImageFont.truetype("FreeMono.ttf", 40)
d = ImageDraw.Draw(im)
d.text((10, 10), "Hello World", font=font)
b = BytesIO()
im.save(b, "PNG")
data = base64.b64encode(b.getvalue())
print(b"background-image: url(data:image/gif;base64,"+data+b")")
import urllib.request
urllib.request.urlretrieve("https://python-pillow.org/images/pillow-logo-light-text-1280x640.png", "pillow.png")
If it would be helpful just to know how to write text onto an image, you can use part of what I wrote above. from PIL import Image, ImageDraw, ImageFont
im = Image.new("RGB", (290, 65))
font = ImageFont.truetype("FreeMono.ttf", 40)
d = ImageDraw.Draw(im)
d.text((10, 10), "Hello World", font=font) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
radarhere
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I don't understand your question.
background-image
CSS property?You mentioned that you wanted to write on the image first though.