Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db6e46d

Browse files
Add files via upload
1 parent a7a7f21 commit db6e46d

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Introduction
2+
3+
from PIL import Image
4+
5+
img = Image.open("226.jpg")
6+
print(img.size)
7+
print(img.format)
8+
9+
img.show() #as the console cant open images, so it opens the photos app to show the image
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Cropping
2+
3+
from PIL import Image
4+
5+
img = Image.open("226.jpg")
6+
area = (100, 100, 400, 400) # The 1st 2 numbers are x,y coordinates of the top left corner and the last 2 are of the bottom right corner
7+
# area is a 4 value tuple
8+
cropped_img = img.crop(area) # The only parameter it takes is a 4 value tuple
9+
10+
img.show()
11+
cropped_img.show()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Combining 2 images together
2+
3+
from PIL import Image
4+
5+
img1 = Image.open("226.jpg")
6+
img2 = Image.open("1234.jpeg")
7+
8+
area = (100, 100, 625, 450) # We have to give a calculated area of the second image to be pasted on the first, otherwise error occurs
9+
img1.paste(img2, area) #it takes 2 parameters. Here we are pasting img2 on img1, with the given area where the img2 will be pasted
10+
11+
img1.show()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Giving Filters to images
2+
# Individual Channels
3+
4+
from PIL import Image
5+
6+
img = Image.open("226.jpg")
7+
print(img.mode) # RGB is the mode
8+
9+
r, g, b = img.split() # It returns a tuple of 3 images i.e, the amount of red, green and blue in the image
10+
11+
r.show()
12+
g.show()
13+
b.show()
14+
15+
# Merging effect -> merging the individual channels of R,G,B to create a filter
16+
17+
img1 = Image.merge("RGB", (r, g, b)) # It takes in the mode and the colours
18+
# In the above case, it will print the same image
19+
20+
img2 = Image.merge("RGB", (b, g, r))
21+
img2.show()
22+
23+
img3 = Image.merge("RGB", (g, r, b))
24+
img3.show()
25+
26+
img4 = Image.merge("RGB", (b, g, b))
27+
img4.show()
28+
29+
# It just takes in the amount of R,G,B in the given given format(RGB), but different permutations give different results
30+
# Likewise we can use any other permutations, to form different filters of the images
31+
32+
# Double Exposure:
33+
# to use this, the two images must be of the same size
34+
35+
new_img1 = Image.open("1_Earth.jpg")
36+
new_img2 = Image.open("1_mario.jpg")
37+
38+
r1, b1, g1 = new_img1.split()
39+
r2, b2, g2 = new_img2.split()
40+
41+
final_image = Image.merge("RGB", (r1, b2, g1))
42+
final_image.show()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Basic transformations
2+
3+
from PIL import Image
4+
5+
img = Image.open("226.jpg")
6+
7+
# Squarring the image -> just compresses the image size without cropping it
8+
9+
square_img = img.resize((400, 400)) # Takes in a tuple
10+
square_img.show()
11+
12+
# For any kind of rotation or flipping of image, always use "transpose" function
13+
14+
# Flip
15+
16+
flip_img1 = img.transpose(Image.FLIP_LEFT_RIGHT)
17+
flip_img2 = img.transpose(Image.FLIP_TOP_BOTTOM)
18+
flip_img1.show()
19+
flip_img2.show()
20+
21+
# Rotate
22+
23+
spin_img1 = img.transpose(Image.ROTATE_90)
24+
spin_img2 = img.transpose(Image.ROTATE_180)
25+
spin_img3 = img.transpose(Image.ROTATE_270)
26+
27+
spin_img1.show()
28+
spin_img2.show()
29+
spin_img3.show()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Modes and Filters
2+
3+
from PIL import Image
4+
from PIL import ImageFilter # Contains pretty cool built in filters
5+
img = Image.open("226.jpg")
6+
7+
#Converting to black and white
8+
9+
black_white = img.convert("L") # It takes in the format of the image you want to convert into. Eg: RGB, CMYK, L
10+
# L -> Luminance, which basically means black and white
11+
# CMYK -> Cyan, Magenta, Yellow, Key(Black), which is generally used in colour printing, pretty much same as RGB
12+
13+
black_white.show()
14+
15+
cmyk_img = img.convert("CMYK")
16+
cmyk_img.show()
17+
18+
# Using image filters
19+
20+
blur_img = img.filter(ImageFilter.BLUR)
21+
blur_img.show()
22+
23+
detail_img = img.filter(ImageFilter.DETAIL)
24+
detail_img.show()
25+
26+
edges_img = img.filter(ImageFilter.FIND_EDGES)
27+
edges_img.show()

0 commit comments

Comments
(0)

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