Hello. I am creating a "dial", like on a speedometer. I am trying to rotate the dial, but it doesn't seem like it's rotating correctly. I am trying to rotate it on the bottom middle point like a speedometer. The output looks like expand=True is not fully expanding
im = Image.open("needle.png")
width = im.width
height = im.height
x = width / 2
y = height
loc = (x, y)
im.rotate(45, center=loc, expand=True).show()
Any thoughts?
Investigating, I find http://pillow.readthedocs.io/en/5.1.x/reference/Image.html?highlight=rotate#PIL.Image.Image.rotate - 'Note that the expand flag assumes rotation around the center and no translation.'
It's entirely possible you'll figure out your own solution to this problem now, but to be helpful, my suggestion would be to manually make the image larger first, so that you don't need to worry about automatic expanding -
from PIL import Image
im = Image.open("needle.png")
width = im.width
height = im.height
expandedIm = Image.new(im.mode, (im.height*2, im.height))
pasteX = int(height-width/2)
pasteY = 0
expandedIm.paste(im, (pasteX, pasteY))
x = width / 2
y = height
loc = (x+pasteX, y+pasteY)
expandedIm.rotate(45, center=loc).show()
Well, the basic way to do that would be using pixel access - https://pillow.readthedocs.io/en/3.0.x/reference/PixelAccess.html
from PIL import Image
im = Image.linear_gradient('L').convert('RGB')
out = Image.new('RGB', im.size)
px_in = im.load()
px_out = out.load()
for x in range(0, im.width):
for y in range(0, im.height):
r, g, b = px_in[x, y]
px_out[x, y] = (r, int(g / 2), int(b / 4))
out.save('out.png')
Otherwise, perhaps https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageFilter.py#L304
Hi. I don't quite understand your question. However, I will attempt to answer.
To read an entire file in Python -
with open('in.txt', 'r') as f:
data = f.read()
To write that data back to a file -
with open('out.txt', 'w') as f:
f.write(data)
If you are having trouble because your data is bytes, not a string -
with open('out.txt', 'wb') as f:
f.write(data)
Also, if your question relates to Pillow in some way, please explain further, because I don't see it.
When you say UV map, you’re talking about Blender, yes? Are you sure this is a Pillow question, and not a Blender question?
A bit of Googling, and https://blender.stackexchange.com/questions/7855/how-can-i-set-the-image-to-use-the-uv-map-using-the-python-api seems interesting.
.show()
each frame and none of them show this blend of frames.
snaps[0].save('build/sprite.gif', transparency=0, save_all=True, append_images=snaps[1:], loop=0)
snaps = list()
for q in quadrants:
crop = image.crop(q)
alpha = crop.getchannel('A')
mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
crop.paste(0, mask)
crop.info['transparency'] = 255
snaps.append(crop)
snaps[0].save('build/sprite.gif', transparency=0, save_all=True, append_images=snaps[1:], loop=0)
from PIL import Image
image = Image.open('walking-sprite.png')
snaps = []
for i in range(0, 8):
crop = image.crop((i * 28, 111-28, (i+1)*28, 111))
alpha = crop.getchannel('A')
mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
crop.paste(0, mask)
crop.info['transparency'] = 255
snaps.append(crop)
snaps[0].save('sprite.gif', transparency=0, save_all=True, append_images=snaps[1:], loop=0, disposal=2)