Skip to content

Commit b61ba4a

Browse files
committed
Merge pull request #55 from cgohlke/patch-3
Fix pildriver script
2 parents 9becfc3 + 03b8960 commit b61ba4a

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

Scripts/pildriver.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def do_verbose(self):
6161
6262
Set verbosity flag from top of stack.
6363
"""
64-
self.verbose = self.do_pop()
64+
self.verbose = int(self.do_pop())
6565

6666
# The evaluation stack (internal only)
6767

@@ -206,7 +206,7 @@ def do_filter(self):
206206
207207
Process the top image with the given filter.
208208
"""
209-
import ImageFilter
209+
from PIL import ImageFilter
210210
filter = eval("ImageFilter." + self.do_pop().upper())
211211
image = self.do_pop()
212212
self.push(image.filter(filter))
@@ -326,21 +326,21 @@ def do_format(self):
326326
327327
Push the format of the top image onto the stack.
328328
"""
329-
self.push(self.pop().format)
329+
self.push(self.do_pop().format)
330330

331331
def do_mode(self):
332332
"""usage: mode <image:pic1>
333333
334334
Push the mode of the top image onto the stack.
335335
"""
336-
self.push(self.pop().mode)
336+
self.push(self.do_pop().mode)
337337

338338
def do_size(self):
339339
"""usage: size <image:pic1>
340340
341341
Push the image size on the stack as (y, x).
342342
"""
343-
size = self.pop().size
343+
size = self.do_pop().size
344344
self.push(size[0])
345345
self.push(size[1])
346346

@@ -351,15 +351,15 @@ def do_invert(self):
351351
352352
Invert the top image.
353353
"""
354-
import ImageChops
354+
from PIL import ImageChops
355355
self.push(ImageChops.invert(self.do_pop()))
356356

357357
def do_lighter(self):
358358
"""usage: lighter <image:pic1> <image:pic2>
359359
360360
Pop the two top images, push an image of the lighter pixels of both.
361361
"""
362-
import ImageChops
362+
from PIL import ImageChops
363363
image1 = self.do_pop()
364364
image2 = self.do_pop()
365365
self.push(ImageChops.lighter(image1, image2))
@@ -369,7 +369,7 @@ def do_darker(self):
369369
370370
Pop the two top images, push an image of the darker pixels of both.
371371
"""
372-
import ImageChops
372+
from PIL import ImageChops
373373
image1 = self.do_pop()
374374
image2 = self.do_pop()
375375
self.push(ImageChops.darker(image1, image2))
@@ -379,7 +379,7 @@ def do_difference(self):
379379
380380
Pop the two top images, push the difference image
381381
"""
382-
import ImageChops
382+
from PIL import ImageChops
383383
image1 = self.do_pop()
384384
image2 = self.do_pop()
385385
self.push(ImageChops.difference(image1, image2))
@@ -389,7 +389,7 @@ def do_multiply(self):
389389
390390
Pop the two top images, push the multiplication image.
391391
"""
392-
import ImageChops
392+
from PIL import ImageChops
393393
image1 = self.do_pop()
394394
image2 = self.do_pop()
395395
self.push(ImageChops.multiply(image1, image2))
@@ -399,7 +399,7 @@ def do_screen(self):
399399
400400
Pop the two top images, superimpose their inverted versions.
401401
"""
402-
import ImageChops
402+
from PIL import ImageChops
403403
image2 = self.do_pop()
404404
image1 = self.do_pop()
405405
self.push(ImageChops.screen(image1, image2))
@@ -409,7 +409,7 @@ def do_add(self):
409409
410410
Pop the two top images, produce the scaled sum with offset.
411411
"""
412-
import ImageChops
412+
from PIL import ImageChops
413413
image1 = self.do_pop()
414414
image2 = self.do_pop()
415415
scale = float(self.do_pop())
@@ -421,7 +421,7 @@ def do_subtract(self):
421421
422422
Pop the two top images, produce the scaled difference with offset.
423423
"""
424-
import ImageChops
424+
from PIL import ImageChops
425425
image1 = self.do_pop()
426426
image2 = self.do_pop()
427427
scale = float(self.do_pop())
@@ -435,7 +435,7 @@ def do_color(self):
435435
436436
Enhance color in the top image.
437437
"""
438-
import ImageEnhance
438+
from PIL import ImageEnhance
439439
factor = float(self.do_pop())
440440
image = self.do_pop()
441441
enhancer = ImageEnhance.Color(image)
@@ -446,32 +446,32 @@ def do_contrast(self):
446446
447447
Enhance contrast in the top image.
448448
"""
449-
import ImageEnhance
449+
from PIL import ImageEnhance
450450
factor = float(self.do_pop())
451451
image = self.do_pop()
452-
enhancer = ImageEnhance.Color(image)
452+
enhancer = ImageEnhance.Contrast(image)
453453
self.push(enhancer.enhance(factor))
454454

455455
def do_brightness(self):
456456
"""usage: brightness <image:pic1>
457457
458458
Enhance brightness in the top image.
459459
"""
460-
import ImageEnhance
460+
from PIL import ImageEnhance
461461
factor = float(self.do_pop())
462462
image = self.do_pop()
463-
enhancer = ImageEnhance.Color(image)
463+
enhancer = ImageEnhance.Brightness(image)
464464
self.push(enhancer.enhance(factor))
465465

466466
def do_sharpness(self):
467467
"""usage: sharpness <image:pic1>
468468
469469
Enhance sharpness in the top image.
470470
"""
471-
import ImageEnhance
471+
from PIL import ImageEnhance
472472
factor = float(self.do_pop())
473473
image = self.do_pop()
474-
enhancer = ImageEnhance.Color(image)
474+
enhancer = ImageEnhance.Sharpness(image)
475475
self.push(enhancer.enhance(factor))
476476

477477
# The interpreter loop
@@ -512,7 +512,10 @@ def execute(self, list):
512512
print("PILDriver says hello.")
513513
while True:
514514
try:
515-
line = raw_input('pildriver> ');
515+
if sys.version_info[0] >= 3:
516+
line = input('pildriver> ');
517+
else:
518+
line = raw_input('pildriver> ');
516519
except EOFError:
517520
print("\nPILDriver says goodbye.")
518521
break

0 commit comments

Comments
 (0)