Skip to content

Commit 1dd5caf

Browse files
committed
updating examples [ci skip]
1 parent 15f094e commit 1dd5caf

12 files changed

+51
-26
lines changed

examples/heif_add_del_thumbnails.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
if __name__ == "__main__":
1010
os.makedirs(TARGET_FOLDER, exist_ok=True)
11-
image_path = Path("images/rgb8_512_512_1_0.heic")
12-
heif_image = pillow_heif.open_heif(image_path)
11+
image_path = Path("images/heif_other/nokia/alpha.heic")
12+
heif_file = pillow_heif.open_heif(image_path)
1313
result_path = os.path.join(TARGET_FOLDER, f"{image_path.stem}.heic")
14-
heif_image.add_thumbnails([256, 372])
15-
heif_image.save(result_path, quality=35)
14+
pillow_heif.add_thumbnails(heif_file, [256, 372])
15+
heif_file.save(result_path, quality=35)
1616

1717
# Next code will remove thumbnails
18-
heif_image = pillow_heif.open_heif(result_path)
19-
del heif_image[0].thumbnails[0] # remove first thumbnail
20-
del heif_image[0].thumbnails[0] # remove second thumbnail
18+
heif_file = pillow_heif.open_heif(result_path)
19+
del heif_file.thumbnails[0] # remove first thumbnail
20+
del heif_file.thumbnails[0] # remove second thumbnail
2121
result_path = os.path.join(TARGET_FOLDER, f"{image_path.stem}_no_thumbs.heic")
22-
heif_image.save(result_path, quality=35)
22+
heif_file.save(result_path, quality=35)

examples/heif_create_sequence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
os.chdir(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests"))
99
TARGET_FOLDER = "../converted"
1010

11-
# Create HEIF file containing `RGB_8.png` and `RGBA_8.png`
11+
# Create HEIF file containing `RGB_16.png` and `RGBA_16.png`
1212
if __name__ == "__main__":
1313
os.makedirs(TARGET_FOLDER, exist_ok=True)
14-
image1_path = Path("images/jpeg_gif_png/RGB_8.png")
15-
image2_path = Path("images/jpeg_gif_png/RGBA_8.png")
14+
image1_path = Path("images/non_heif/RGB_16.png")
15+
image2_path = Path("images/non_heif/RGBA_16.png")
1616
img1 = Image.open(image1_path)
1717
img2 = Image.open(image2_path)
1818
result_path = os.path.join(TARGET_FOLDER, "RGB_A_8.heic")

examples/heif_dump_info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
if __name__ == "__main__":
1010
file = sys.argv[1]
11-
# file = "../tests/images/rgb8_128_128_2_1.heic"
1211
print("Dumping info for file:", file)
1312
print("Check result:", pillow_heif.HeifFiletype(pillow_heif.check_heif(file)))
1413
print("Supported:", pillow_heif.is_supported(file))

examples/heif_enumerate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# This demo displays all thumbnails and all images.
99
if __name__ == "__main__":
10-
image_path = Path("images/etc_heif/nokia/alpha_3_2.heic")
10+
image_path = Path("images/heif_other/nokia/alpha.heic")
1111
heif_image = pillow_heif.open_heif(image_path)
1212
print(f"number of images in file: {len(heif_image)}")
1313
for i, image in enumerate(heif_image):

examples/heif_remove_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
os.chdir(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests"))
77
TARGET_FOLDER = "../converted"
88

9-
# rgb8_128_128_2_1 contains two images, we remove image with index `0`
9+
# zPug_3 contains three images, we remove first image
1010
if __name__ == "__main__":
1111
os.makedirs(TARGET_FOLDER, exist_ok=True)
12-
image_path = Path("images/rgb8_128_128_2_1.heic")
12+
image_path = Path("images/heif/zPug_3.heic")
1313
heif_image = pillow_heif.open_heif(image_path)
1414
result_path = os.path.join(TARGET_FOLDER, f"{image_path.stem}.heic")
1515
del heif_image[0]

examples/heif_save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Save from heic to new heic with lower quality.
1010
if __name__ == "__main__":
1111
os.makedirs(TARGET_FOLDER, exist_ok=True)
12-
image_path = Path("images/etc_heif/cat.hif")
12+
image_path = Path("images/heif_other/cat.hif")
1313
# cat.hif is a 10 bit image, it will be saved as 8 bit.
1414
# change convert_hdr_to_8bit to False to save it in original depth.
1515
heif_file = pillow_heif.open_heif(image_path, convert_hdr_to_8bit=True)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
from pathlib import Path
3+
4+
from PIL import Image, ImageSequence
5+
6+
import pillow_heif
7+
8+
pillow_heif.register_heif_opener()
9+
10+
os.chdir(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests"))
11+
TARGET_FOLDER = "../converted"
12+
13+
if __name__ == "__main__":
14+
os.makedirs(TARGET_FOLDER, exist_ok=True)
15+
image_path = Path("images/heif_other/nokia/alpha.heic")
16+
im = Image.open(image_path)
17+
result_path = os.path.join(TARGET_FOLDER, f"{image_path.stem}.heic")
18+
for frame in ImageSequence.Iterator(im):
19+
pillow_heif.add_thumbnails(frame, [256, 372])
20+
im.save(result_path, quality=35, save_all=True)
21+
22+
# Next code will remove thumbnails
23+
im = Image.open(result_path)
24+
del im.info["thumbnails"][0] # remove first thumbnail
25+
del im.info["thumbnails"][0] # remove second thumbnail
26+
result_path = os.path.join(TARGET_FOLDER, f"{image_path.stem}_no_thumbs.heic")
27+
im.save(result_path, quality=35, save_all=True)

examples/pillow_create_sequence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
os.chdir(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests"))
99
TARGET_FOLDER = "../converted"
1010

11-
# Create HEIF file containing `RGB_8.png` and `RGBA_8.png`
11+
# Create HEIF file containing `RGB_16.png` and `RGBA_16.png`
1212
if __name__ == "__main__":
1313
os.makedirs(TARGET_FOLDER, exist_ok=True)
14-
image1_path = Path("images/jpeg_gif_png/RGB_8.png")
15-
image2_path = Path("images/jpeg_gif_png/RGBA_8.png")
14+
image1_path = Path("images/non_heif/RGB_16.png")
15+
image2_path = Path("images/non_heif/RGBA_16.png")
1616
img1 = Image.open(image1_path)
1717
img2 = Image.open(image2_path)
1818
result_path = os.path.join(TARGET_FOLDER, "RGB_A_8.heic")

examples/pillow_dump_info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
if __name__ == "__main__":
1010
file = sys.argv[1]
11-
# file = "../tests/images/rgb8_128_128_2_1.heic"
1211
print("Dumping info for file:", file)
1312
heif_pillow = Image.open(file)
1413
print("Number of images:", len([i for i in ImageSequence.Iterator(heif_pillow)]))

examples/pillow_enumerate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# This demo displays all thumbnails and all images from file.
1111
if __name__ == "__main__":
1212
pillow_heif.register_heif_opener()
13-
image_path = Path("images/etc_heif/nokia/alpha_3_2.heic")
13+
image_path = Path("images/heif_other/nokia/alpha.heic")
1414
img = Image.open(image_path)
1515
for i, frame in enumerate(ImageSequence.Iterator(img)):
1616
for thumb in img.info["thumbnails"]:

0 commit comments

Comments
 (0)