mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-01 19:10:10 +03:00
Using relation path in demo; using captcha image instead of lena
This commit is contained in:
parent
cb743697fc
commit
d22ae7a3ad
|
@ -11,16 +11,12 @@ PIL Tutorial
|
|||
- http://nadiana.com/category/pil
|
||||
|
||||
|
||||
## Images used in These Demos
|
||||
## Image used in these demos
|
||||
|
||||
wget http://upload.wikimedia.org/wikipedia/commons/6/69/Captcha.jpg -O image_resources/captcha.jpg
|
||||
|
||||
|
||||
http://www.cs.cmu.edu/~chuck/lennapg/
|
||||
|
||||
wget http://www.cs.cmu.edu/~chuck/lennapg/lena_std.tif -O image_resources/lena_std.tif
|
||||
wget http://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg -O image_resources/len_std.jpg
|
||||
|
||||
|
||||
## Build it on Mac OS X 10.6.8
|
||||
## Build it on Mac OS X 10.6.*
|
||||
|
||||
Build an egg for i386 with Python 2.5/Python 2.6
|
||||
|
||||
|
@ -35,6 +31,6 @@ Build an egg for x86_64 with Python 2.7(install it via MacPorts)
|
|||
python setup.py bdist_egg
|
||||
|
||||
|
||||
## Install it via Package Management System
|
||||
## Install it via package management system
|
||||
|
||||
HomeBrew is cool, you could use it instead of MacPorts on OS X.
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp = file_path)
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
file_path = os.path.join(parent_path, "image_resources", "l_hires.jpg")
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp = file_path)
|
||||
|
||||
left_upper_x, left_upper_y = 400, 100
|
||||
right_lower_x, right_lower_y = 700, 450
|
||||
left_upper_x, left_upper_y = 0, 0
|
||||
right_lower_x, right_lower_y = 100, 50
|
||||
box = (left_upper_x, left_upper_y, right_lower_x, right_lower_y)
|
||||
|
||||
region = im.crop(box)
|
||||
|
||||
new_filename = "x".join([str(i) for i in box]) + ".jpg"
|
||||
region.save(new_filename)
|
||||
region.save(os.path.join(PWD, new_filename))
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
copy image
|
||||
"""
|
||||
import os
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
file_path = os.path.join(parent_path, "image_resources", "l_hires.jpg")
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp = file_path)
|
||||
|
||||
left_upper_x, left_upper_y = 10, 10
|
||||
|
@ -21,4 +18,4 @@ region = region.transpose(Image.ROTATE_90)
|
|||
im.paste(region, box)
|
||||
|
||||
new_filename = "C-c-C-v-left" + ".jpg"
|
||||
im.save(new_filename)
|
||||
im.save(os.path.join(PWD, new_filename))
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
import ImageDraw
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
BLACK = "#000000"
|
||||
WHITE = "#ffffff"
|
||||
|
||||
fg_color = BLACK
|
||||
bg_color = WHITE
|
||||
|
||||
canvas_w, canvas_h = 100, 100
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=bg_color)
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
||||
|
||||
draw = ImageDraw.Draw(im=im)
|
||||
|
||||
|
@ -17,6 +18,6 @@ left_top_x, left_top_y = 10, 10
|
|||
right_bottom_x, right_bottom_y = 30, 100
|
||||
box = (left_top_x, left_top_y, right_bottom_x, right_bottom_y)
|
||||
|
||||
draw.line(xy=box, fill=fg_color, width=1)
|
||||
draw.line(xy=box, fill=BLACK, width=1)
|
||||
|
||||
im.save("draw_line.jpeg")
|
||||
im.save(os.path.join(PWD, "draw_line.jpg"))
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
import ImageDraw
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
BLACK = "#000000"
|
||||
WHITE = "#ffffff"
|
||||
|
||||
fg_color = BLACK
|
||||
bg_color = WHITE
|
||||
|
||||
|
||||
canvas_w, canvas_h = 100, 100
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=bg_color)
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
||||
|
||||
draw = ImageDraw.Draw(im=im)
|
||||
|
||||
|
@ -21,6 +21,6 @@ draw = ImageDraw.Draw(im=im)
|
|||
|
||||
points = ((10, 10), (40, 10), (55, 35), (40,50))
|
||||
for point in points:
|
||||
draw.point(xy=point, fill=fg_color)
|
||||
draw.point(xy=point, fill=BLACK)
|
||||
|
||||
im.save("draw_points.jpeg")
|
||||
im.save(os.path.join(PWD, "draw_points.jpg"))
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
import ImageDraw
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
BLACK = "#000000"
|
||||
WHITE = "#ffffff"
|
||||
RED = "#ff0000"
|
||||
bg_color = WHITE
|
||||
|
||||
|
||||
canvas_w, canvas_h = 100, 100
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=bg_color)
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
||||
|
||||
draw = ImageDraw.Draw(im=im)
|
||||
|
||||
|
@ -19,4 +22,4 @@ draw = ImageDraw.Draw(im=im)
|
|||
|
||||
xy = ((10, 10), (40, 10), (55, 35), (40,50))
|
||||
draw.polygon(xy=xy, fill=RED, outline=BLACK)
|
||||
im.save("draw_polygon.jpeg")
|
||||
im.save(os.path.join(PWD, "draw_polygon.jpg"))
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
import ImageDraw
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
BLACK = "#000000"
|
||||
WHITE = "#ffffff"
|
||||
|
||||
fg_color = BLACK
|
||||
bg_color = WHITE
|
||||
|
||||
|
||||
canvas_w, canvas_h = 100, 100
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=bg_color)
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
||||
|
||||
draw = ImageDraw.Draw(im=im)
|
||||
|
||||
|
@ -18,6 +18,6 @@ left_top_x, left_top_y = 10, 10
|
|||
right_bottom_x, right_bottom_y = 30, 100
|
||||
box = (left_top_x, left_top_y, right_bottom_x, right_bottom_y)
|
||||
|
||||
draw.rectangle(xy=box, fill=fg_color, outline=None)
|
||||
draw.rectangle(xy=box, fill=BLACK, outline=None)
|
||||
|
||||
im.save("draw_rectangle.jpeg")
|
||||
im.save(os.path.join(PWD, "draw_rectangle.jpg"))
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import os
|
||||
import sys
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
BLACK = "#ffffff"
|
||||
WHITE = "#000000"
|
||||
|
||||
|
@ -10,7 +16,7 @@ bg_color = BLACK
|
|||
|
||||
|
||||
canvas_w, canvas_h = 180, 50
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=bg_color)
|
||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
||||
|
||||
draw = ImageDraw.Draw(im=im)
|
||||
|
||||
|
@ -29,6 +35,6 @@ else:
|
|||
font_size = 26
|
||||
font = ImageFont.truetype(filename=filename, size=font_size)
|
||||
|
||||
draw.text(xy=begin, text=text, fill=fg_color, font=font)
|
||||
draw.text(xy=begin, text=text, fill=BLACK, font=font)
|
||||
|
||||
im.save("draw_text.bmp")
|
||||
im.save(os.path.join(PWD, "draw_text.bmp"))
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp=file_path)
|
||||
|
||||
#new_im = im.transpose(Image.FLIP_LEFT_RIGHT)
|
||||
|
@ -14,4 +14,4 @@ im = Image.open(fp=file_path)
|
|||
new_im = im.transpose(Image.FLIP_TOP_BOTTOM)
|
||||
new_filename = os.path.splitext(os.path.basename(file_path))[0] + '-' + "flip_top_bottom" + ".jpg"
|
||||
|
||||
new_im.save(new_filename)
|
||||
new_im.save(os.path.join(PWD, new_filename))
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
file_path = os.path.join(parent_path, "image_resources", "l_hires.jpg")
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp=file_path)
|
||||
|
||||
|
@ -14,5 +14,6 @@ im = Image.open(fp=file_path)
|
|||
new_im = im.convert("L")
|
||||
new_file_name = os.path.splitext(os.path.basename(file_path))[0]
|
||||
new_file_name = new_file_name + '-' + 'grayscale' + '.bmp'
|
||||
new_im.save(new_file_name)
|
||||
|
||||
new_im.save(os.path.join(PWD, new_file_name))
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image, ImageDraw
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
BLACK = 0
|
||||
|
@ -52,4 +52,4 @@ for x in xrange(w):
|
|||
new_file_name = os.path.splitext(os.path.basename(file_path))[0]
|
||||
new_file_name = new_file_name + '-' + 'histogram' + '.bmp'
|
||||
|
||||
hist_im.save(new_file_name)
|
||||
hist_im.save(os.path.join(PWD, new_file_name))
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp=file_path)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
|
||||
|
||||
im = Image.open(fp=file_path)
|
||||
|
@ -12,4 +13,4 @@ degress = 90
|
|||
new_im = im.rotate(degress)
|
||||
|
||||
new_filename = os.path.splitext(os.path.basename(file_path))[0] + "-rotate-" + str(degress) + ".jpg"
|
||||
new_im.save(new_filename)
|
||||
new_im.save(os.path.join(PWD, new_filename))
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import Image
|
||||
|
||||
|
||||
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_path = os.path.dirname(PWD)
|
||||
|
||||
import Image
|
||||
|
||||
file_path = os.path.join(parent_path, "image_resources", 'l_hires.jpg')
|
||||
file_path = os.path.join(parent_path, "image_resources", 'captcha.jpg')
|
||||
im = Image.open(fp=file_path)
|
||||
|
||||
width, height = im.size[0], im.size[1]
|
||||
new_size = (width/8, height/8)
|
||||
new_size = (width/4, height/4)
|
||||
|
||||
im.thumbnail(new_size)
|
||||
|
||||
|
@ -17,4 +18,4 @@ new_filename= "x".join([str(i) for i in new_size])
|
|||
new_filename = os.path.splitext(os.path.basename(file_path))[0] + '-' + new_filename + ".jpg"
|
||||
new_file_path = os.path.join(PWD, new_filename)
|
||||
|
||||
im.save(new_filename)
|
||||
im.save(os.path.join(PWD, new_filename))
|
Loading…
Reference in New Issue
Block a user