@@ -36,15 +36,14 @@ python3 -m pip install pillow-heif
3636
3737## Example of use as a Pillow plugin
3838``` python3
39- from PIL import Image, ImageSequence
39+ from PIL import Image
4040from pillow_heif import register_heif_opener
4141
4242register_heif_opener()
4343
44- image = Image.open(" images/input.heic" ) # do whatever need with a Pillow image
45- for i, frame in enumerate (ImageSequence.Iterator(image)):
46- rotated = frame.rotate(13 )
47- rotated.save(f " rotated_frame { i} .heic " , quality = 90 )
44+ im = Image.open(" images/input.heic" ) # do whatever need with a Pillow image
45+ im = im.rotate(13 )
46+ im.save(f " rotated_image.heic " , quality = 90 )
4847```
4948
5049## 16 bit PNG to 10 bit HEIF using OpenCV
@@ -68,8 +67,8 @@ import cv2
6867import pillow_heif
6968
7069heif_file = pillow_heif.open_heif(" images/rgb12.heif" , convert_hdr_to_8bit = False )
71- heif_file[ 0 ] .convert_to(" BGRA;16" if heif_file[ 0 ] .has_alpha else " BGR;16" )
72- np_array = np.asarray(heif_file[ 0 ] )
70+ heif_file.convert_to(" BGRA;16" if heif_file.has_alpha else " BGR;16" )
71+ np_array = np.asarray(heif_file)
7372cv2.imwrite(" rgb16.png" , np_array)
7473```
7574
@@ -79,37 +78,50 @@ import pillow_heif
7978
8079if pillow_heif.is_supported(" images/rgb10.heif" ):
8180 heif_file = pillow_heif.open_heif(" images/rgb10.heif" , convert_hdr_to_8bit = False )
82- print (" image mode:" , heif_file[ 0 ] .mode)
83- print (" image data length:" , len (heif_file[ 0 ] .data))
84- print (" image data stride:" , heif_file[ 0 ] .stride)
85- heif_file[ 0 ] .convert_to(" RGB;16" ) # convert 10 bit image to RGB 16 bit.
86- print (" image mode:" , heif_file[ 0 ] .mode)
81+ print (" image mode:" , heif_file.mode)
82+ print (" image data length:" , len (heif_file.data))
83+ print (" image data stride:" , heif_file.stride)
84+ heif_file.convert_to(" RGB;16" ) # convert 10 bit image to RGB 16 bit.
85+ print (" image mode:" , heif_file.mode)
8786```
8887
8988## Get decoded image data as a Numpy array
9089``` python3
9190import numpy as np
9291import pillow_heif
9392
94- if pillow_heif.is_supported(" images/rgb8_512_512_1_0 .heic" ):
95- heif_file = pillow_heif.open_heif(" images/rgb8_512_512_1_0 .heic" )
96- np_array = np.asarray(heif_file[ 0 ] )
93+ if pillow_heif.is_supported(" input .heic" ):
94+ heif_file = pillow_heif.open_heif(" input .heic" )
95+ np_array = np.asarray(heif_file)
9796```
9897
99- ## Scaling and adding thumbnails
98+ ## Adding & Removing thumbnails
10099``` python3
101100import pillow_heif
102101
103102if pillow_heif.is_supported(" input.heic" ):
104103 heif_file = pillow_heif.open_heif(" input.heic" )
105- for img in heif_file: # you still can use it without iteration, like before.
106- img.scale(1024 , 768 ) # scaling each image in file.
107- heif_file.add_thumbnails([768 , 512 , 256 ]) # add three new thumbnail boxes.
108- # default quality is probably ~77 in x265, set it a bit lower.
109- heif_file.save(" output.heic" , quality = 70 , save_all = False ) # save_all is True by default.
104+ pillow_heif.add_thumbnails(heif_file, [768 , 512 , 256 ]) # add three new thumbnail boxes.
105+ heif_file.save(" output_with_thumbnails.heic" )
106+ heif_file.thumbnails.clear() # clear list with thumbnails.
107+ heif_file.save(" output_without_thumbnails.heic" )
108+ ```
109+
110+ ## (Pillow)Adding & Removing thumbnails
111+ ``` python3
112+ from PIL import Image
113+ import pillow_heif
114+
115+ pillow_heif.register_heif_opener()
116+
117+ im = Image.open(" input.heic" )
118+ pillow_heif.add_thumbnails(im, [768 , 512 , 256 ]) # add three new thumbnail boxes.
119+ im.save(" output_with_thumbnails.heic" )
120+ im.info[" thumbnails" ].clear() # clear list with thumbnails.
121+ im.save(" output_without_thumbnails.heic" )
110122```
111123
112- ## Using thumbnails when they are present in a file(from version 0.5.0)
124+ ## Using thumbnails when they are present in a file
113125``` python3
114126import pillow_heif
115127
@@ -120,7 +132,7 @@ if pillow_heif.is_supported("input.heic"):
120132 print (img) # This will be a thumbnail or if thumbnail is not avalaible then an original.
121133```
122134
123- ## (Pillow)Using thumbnails when they are present in a file(from version 0.5.0)
135+ ## (Pillow)Using thumbnails when they are present in a file
124136``` python3
125137from PIL import Image, ImageSequence
126138import pillow_heif
0 commit comments