Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#python 2+PIL, 268

python 2+PIL, 268

Now I massively use PIL, using image flipping and alpha blending

from PIL import Image
I=Image
B,T=I.blend,I.FLIP_TOP_BOTTOM
a=I.open(raw_input()).convert('RGB')
exec'[email protected]_LEFT_RIGHT);c=a@T);d=b@T)'.replace('@','.transpose(')
x,y=a.size
print'P3',x,y,255
for r,g,b in list(B(B(B(a,b,0.5),c,0.25),d,0.25).getdata()):print r,g,b

Resulting images are available here

#python 2+PIL, 268

Now I massively use PIL, using image flipping and alpha blending

from PIL import Image
I=Image
B,T=I.blend,I.FLIP_TOP_BOTTOM
a=I.open(raw_input()).convert('RGB')
exec'[email protected]_LEFT_RIGHT);c=a@T);d=b@T)'.replace('@','.transpose(')
x,y=a.size
print'P3',x,y,255
for r,g,b in list(B(B(B(a,b,0.5),c,0.25),d,0.25).getdata()):print r,g,b

Resulting images are available here

python 2+PIL, 268

Now I massively use PIL, using image flipping and alpha blending

from PIL import Image
I=Image
B,T=I.blend,I.FLIP_TOP_BOTTOM
a=I.open(raw_input()).convert('RGB')
exec'[email protected]_LEFT_RIGHT);c=a@T);d=b@T)'.replace('@','.transpose(')
x,y=a.size
print'P3',x,y,255
for r,g,b in list(B(B(B(a,b,0.5),c,0.25),d,0.25).getdata()):print r,g,b

Resulting images are available here

deleted 96 characters in body
Source Link
dieter
  • 2k
  • 17
  • 19

#python 2+PIL, 375

extra slow, as it is golfed to death.268

It fills a dict with the color valuesNow I massively use PIL, and spits the image using a print statementimage flipping and alpha blending

from PIL import Image
b=ImageI=Image
B,T=I.blend,I.FLIP_TOP_BOTTOM
a=I.open(raw_input())
H,W=b.size
J,R,M={},range,map
u=[convert(i,j'RGB')for i in R(H
exec'[email protected]_LEFT_RIGHT)for j in R(W;c=a@T)]
j=lambda s:' ;d=b@T)'.join(mapreplace(str'@',s))
def a'.transpose(*p'):
 for x in p:exec'J[x]=tuple(M(%sx:,y=a.size
print'P3',x/4,reduce(%say,b:[x+y 255
for xr,yg,b in zip(a,b)],Mlist(%sx:b.loadB()[x],p),[0]*3)))'%B(B('lambda 'a,)*4)
[a((ib,j0.5),(W-i-1c,j0.25),(id,H-j-10.25),.getdata(W-i-1,H-j-1))for i,j in:print u]
print'P3',Wr,Hg,j([j(Q[p])for p in u])b

Resulting images are available here

#python 2+PIL, 375

extra slow, as it is golfed to death.

It fills a dict with the color values, and spits the image using a print statement

from PIL import Image
b=Image.open(raw_input())
H,W=b.size
J,R,M={},range,map
u=[(i,j)for i in R(H)for j in R(W)]
j=lambda s:' '.join(map(str,s))
def a(*p):
 for x in p:exec'J[x]=tuple(M(%sx:x/4,reduce(%sa,b:[x+y for x,y in zip(a,b)],M(%sx:b.load()[x],p),[0]*3)))'%(('lambda ',)*4)
[a((i,j),(W-i-1,j),(i,H-j-1),(W-i-1,H-j-1))for i,j in u]
print'P3',W,H,j([j(Q[p])for p in u])

#python 2+PIL, 268

Now I massively use PIL, using image flipping and alpha blending

from PIL import Image
I=Image
B,T=I.blend,I.FLIP_TOP_BOTTOM
a=I.open(raw_input()).convert('RGB')
exec'[email protected]_LEFT_RIGHT);c=a@T);d=b@T)'.replace('@','.transpose(')
x,y=a.size
print'P3',x,y,255
for r,g,b in list(B(B(B(a,b,0.5),c,0.25),d,0.25).getdata()):print r,g,b

Resulting images are available here

added 9 characters in body
Source Link
dieter
  • 2k
  • 17
  • 19

#python 2+PIL, 361375

extra slow, as it is golfed to death.

It fills a dict with the color values, and spits the image using a print statement

from PIL import Image
b=Image.open(raw_input())
H,W=b.size
J,R,M={},range,map
u=[(i,j)for i in R(H)for j in R(W)]
j=lambda s:' '.join(map(str,s))
def a(*p):
 for x in p:exec'j=%ss:' '.join(s);J[x]=tupleexec'J[x]=tuple(M(%sx:x/4,reduce(%sa,b:[x+y for x,y in zip(a,b)],M(%sx:b.load()[x],p),[0]*3)))'%(('lambda ',)*4)
[a((i,j),(W-i-1,j),(i,H-j-1),(W-i-1,H-j-1))for i,j in u]
print'P3',W,H,j([j(Q[p])for p in u])

#python 2+PIL, 361

extra slow, as it is golfed to death.

It fills a dict with the color values, and spits the image using a print statement

from PIL import Image
b=Image.open(raw_input())
H,W=b.size
J,R,M={},range,map
u=[(i,j)for i in R(H)for j in R(W)]
def a(*p):
 for x in p:exec'j=%ss:' '.join(s);J[x]=tuple(M(%sx:x/4,reduce(%sa,b:[x+y for x,y in zip(a,b)],M(%sx:b.load()[x],p),[0]*3)))'%(('lambda ',)*4)
[a((i,j),(W-i-1,j),(i,H-j-1),(W-i-1,H-j-1))for i,j in u]
print'P3',W,H,j([j(Q[p])for p in u])

#python 2+PIL, 375

extra slow, as it is golfed to death.

It fills a dict with the color values, and spits the image using a print statement

from PIL import Image
b=Image.open(raw_input())
H,W=b.size
J,R,M={},range,map
u=[(i,j)for i in R(H)for j in R(W)]
j=lambda s:' '.join(map(str,s))
def a(*p):
 for x in p:exec'J[x]=tuple(M(%sx:x/4,reduce(%sa,b:[x+y for x,y in zip(a,b)],M(%sx:b.load()[x],p),[0]*3)))'%(('lambda ',)*4)
[a((i,j),(W-i-1,j),(i,H-j-1),(W-i-1,H-j-1))for i,j in u]
print'P3',W,H,j([j(Q[p])for p in u])
Source Link
dieter
  • 2k
  • 17
  • 19
Loading

AltStyle によって変換されたページ (->オリジナル) /