-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
994 lines (990 loc) · 44.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pillow Demo</title>
<link rel="stylesheet" href="dist/bundle.css">
<style>
img {
border-radius: 33px;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<!------------------------------------------------------------------------------->
<section>
<div>
<img width="66%" src="img/pillow-logo-light-text.png">
</div>
<h3>Demo</h3>
<p>Presented to SacPy Meetup 10/03/24</p>
<aside class="notes">
<div>Welcome to the Pillow Demo!</div>
<div>My name is Alex. I live in Bethesda, MD, USA.</div>
<div>
I am the creator of Python Pillow, a fork of the Python Imaging Library I
created in 2010.
</div>
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<h3>About This Talk</h3>
<p class="fragment">Past, Present and Future</p>
<ul>
<li class="fragment">Pillow created July 31, 2010</li>
<li class="fragment">PIL created June 15, 1995</li>
<li class="fragment">Python created February 20, 1991</li>
</ul>
<aside class="notes">
Pillow 1.0 was released on July 31, 2010. PIL's 10 year anniversary was June 15, 2005 according to Fredrik on Image SIG. Python 0.9.0 was published to the alt.sources newsgroup on February 20, 1991, after about a year of development starting in December 1989.
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<h3>About This Talk</h3>
<p class="fragment">14 years of Pillow, 29 years of PIL 🥳</p>
<ul>
<li class="fragment">This stuff is old</li>
<li class="fragment">
But continuously updated
<ul>
<li class="fragment">
<a target="_blank"
href="https://github.com/python-pillow/Pillow/discussions/8221?converting=1">Python 3 support</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://github.com/python-pillow/Pillow/issues/2625">Added type hints</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://github.com/python-pillow/Pillow/issues/1888">High bit depth multichannel images</a>
</li>
</ul>
</li>
<li class="fragment">
Demo based on <a href="https://pillow.readthedocs.io/en/latest/handbook/tutorial.html">handbook tutorial</a>
</li>
</ul>
<aside class="notes">
Check out the tutorial!
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<h3>About Me</h3>
<img src="img/sol.gif" width="16%">
<p class="fragment">Me circa 1998 ↑🤔</p>
<ul>
<li class="fragment">Alex</li>
<li class="fragment">
Jeffrey A. Clark <span class="fragment">(↖same thing)</span>
</li>
<li class="fragment">Bachelor of Science Computer Science 1998 Loyola University Maryland</li>
</ul>
<aside class="notes">
We're going to talk about Pillow but first here's a bit about me. Here I am in 1998, three years after the first PIL release.
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<h3>About Me</h3>
<img src="img/slide12.jpg" width="33%">
<p class="fragment">Me circa 2008 ↖(left)🤔</p>
<ul>
<li class="fragment">Python Pillow Creator 2010</li>
<li class="fragment">
PIL fork author <span class="fragment">(↑same thing)</span>
</li>
<li class="fragment">
Tidelift Lifter 2019 <span class="fragment">($$$ for Pillow)</span>
</li>
</ul>
<aside class="notes">
Here I am in 2008, two years before the first Pillow release. In 2010 I forked PIL to create Pillow. I've been paid by Tidelift to work on Pillow since 2019.
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<h3>About Me</h3>
<img src="img/alex-pillow.jpg" width="33%">
<p class="fragment">Me circa 2020</p>
<p class="fragment">
<a href="https://www.youtube.com/watch?v=D0YwZhksDs8" target="_blank">Plone Conference 2020 — State of Pillow</a>
<a href="https://github.com/python-pillow/state-of-pillow/blob/main/state-of-pillow.pdf"
target="_blank">[PDF]</a>
</p>
<ul>
<li class="fragment">
Lifter <span class="fragment">2019</span><span class="fragment"> (actually late 2018)
</li>
<li class="fragment">
Lifter Advocate <span class="fragment">2023</span><span class="fragment">, 2024</span>
</li>
</ul>
<aside class="notes">
Here I am in 2020, one year after Pillow funding began. In addition to being a paid Lifter I'm also a Lifter advocate, which means I advocate on behalf of Tidelift to help "pay the maintainers". I am also looking for work, so if you're able to help me with my job search, please do!
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<img src="img/Tidelift_primary-logo.webp">
<p class="fragment" style="font-size: 200px">❤️</p>
<p class="fragment">Let's pay the maintainers ✨</p>
<aside class="notes">
I love Tidelift, especially their business model which in the past I called "RedHat for everything but the kernel." until XZ happened and now I call it "RedHat for the middle stack." based on a comment by Tidelift's Luis Villa in which he describes lifted software as the "middle stack", meaning, not the kernel, and not large open source projects that already have funding.
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<img src="img/Tidelift_primary-logo.webp">
<p class="fragment">
Are you an open source maintainer? Check out the
<a href="https://tidelift.com/about/resources/surveys">Tidelift surveys</a>
</p>
<aside class="notes">
As it so happens, Tidelift has just published their annual developer survey results.
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Let's talk about Pillow</p>
<img class="fragment" src="img/screenshot1.png">
<a class="fragment" href="https://github.com/python-pillow/pillow-demo">https://github.com/python-pillow/pillow-demo</a>
<aside class="notes">
Let's talk about Pillow. Most code examples in demo.py. Other examples in modules imported from demo.py.
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Let's talk about Pillow</p>
<p class="fragment">Part II</p>
<p class="fragment">
This is totally <span class="fragment">NOT</span>
<a class="fragment"
target="_blank"
href="https://github.com/python-pillow/pillow-demo/tree/4-16-24">the talk I gave three months ago</a>
</p>
<p class="fragment">
That talk <a class="fragment"
href="https://www.youtube.com/watch?v=xVYqh5ElHUU&t=1600s">is here</a>
</p>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Other Code Examples</p>
<ul>
<li class="fragment">
<a target="_blank" href="https://github.com/janbodnar/pillow-examples">https://github.com/janbodnar/pillow-examples</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://realpython.com/image-processing-with-the-python-pillow-library/">https://realpython.com/image-processing-with-the-python-pillow-library/</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://hhsprings.bitbucket.io/docs/programming/examples/python/PIL/">https://hhsprings.bitbucket.io/docs/programming/examples/python/PIL/</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://pillow.readthedocs.io/en/stable/handbook/index.html">https://pillow.readthedocs.io/en/stable/handbook/index.html</a>
</li>
</ul>
</section>
<!------------------------------------------------------------------------------->
<section>
<img width="70%" src="img/screenshot5.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<img width="70%" src="img/screenshot2.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<img width="70%" src="img/screenshot4.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<img width="70%" src="img/screenshot3.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #1 Open image and print info</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> print(im.format, im.size, im.mode)</span>
<span class="fragment">PPM (128, 128) RGB</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #2 Rotate image 90 degrees clockwise (270 degrees counter clockwise)</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> im = im.rotate(270)</span>
<span class="fragment">>>> im.save("rotated_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/rotated_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #3 Convert to jpeg</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> im.save("hopper.jpg")</span>
<span class="fragment">$ file hopper.jpg</span>
<span class="fragment">hopper.jpg: JPEG image data, JFIF standard 1.01,
aspect ratio, density 1x1, segment length 16, baseline,
precision 8, 128x128, components 3</span>
</code>
</pre>
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #4 Create thumbnails</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> im.thumbnail([64, 64])</span>
<span class="fragment">>>> im.save("thumbnail_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/thumbnail_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #5 Crop image</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> im = im.crop([0, 0, 64, 64])</span>
<span class="fragment">>>> im.save("cropped_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/cropped_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #6 Pasting image</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> region = region.transpose(Image.Transpose.ROTATE_180)</span>
<span class="fragment">>>> im.paste(region, (0, 0, 64, 64))</span>
<span class="fragment">>>> im.save("pasted_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/pasted_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #7 Roll image</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> from roll import roll</span>
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> im = roll(im, 64)
<span class="fragment">>>> im.save("rolled_hopper.jpg")
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/rolled_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #7 roll.py</p>
<pre class="fragment">
<code>
def roll(im, delta):
"""Roll an image sideways."""
xsize, ysize = im.size
delta = delta % xsize
if delta == 0:
return im
part1 = im.crop((0, 0, delta, ysize))
part2 = im.crop((delta, 0, xsize, ysize))
im.paste(part1, (xsize - delta, 0, xsize, ysize))
im.paste(part2, (0, 0, xsize - delta, ysize))
return im
</code>
</pre>
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #8 Merge images</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> hopper = Image.open("hopper.jpg")</span>
<span class="fragment">>>> alex = Image.open("img/alex-pillow.jpg")</span>
<span class="fragment">>>> im = merge(hopper, alex)</span>
<span class="fragment">>>> im.save("merged_hopper.png")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/merged_hopper.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #8 Merge images (and resize)</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> hopper = Image.open("hopper.jpg")</span>
<span class="fragment">>>> alex = Image.open("img/alex-pillow.jpg")</span>
<span class="fragment">>>> im = merge(hopper, alex)</span>
<span class="fragment">>>> im.save("merged_resized_hopper.png")</span>
<span class="fragment">>>> im = Image.open("merged_resized_hopper.png")
<span class="fragment">>>> im = im.resize([128, 128])</span>
<span class="fragment">>>> im.save("merged_resized_hopper.png")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/merged_resized_hopper.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #9 Split and merge bands</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> r, g, b = im.split()</span>
<span class="fragment">>>> im = Image.merge("RGB", (b, g, r))</span>
<span class="fragment">>>> im.save("rebanded_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/rebanded_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #10 Create JPEG thumbnail with resize</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.resize([64, 64])
<span class="fragment">>>> im.save("resized_hopper.jpg")
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/resized_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #11 Transpose image left to right</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
<span class="fragment">>>> im.save("flip_left_right_hopper.jpg")
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/flip_left_right_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #12 Transpose image top to bottom</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.transpose(Image.Transpose.FLIP_TOP_BOTTOM)
<span class="fragment">>>> im.save("flip_top_bottom_hopper.jpg")
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/flip_top_bottom_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #13 Rotate image 90 degrees with transpose</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.transpose(Image.Transpose.ROTATE_90)</span>
<span class="fragment">>>> im.save("rotated_hopper_90.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/rotated_hopper_90.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #14 Rotate image 180 degrees with transpose</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.transpose(Image.Transpose.ROTATE_180)</span>
<span class="fragment">>>> im.save("rotated_hopper_180.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/rotated_hopper_180.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #15 Rotate image 270 degrees with transpose</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.transpose(Image.Transpose.ROTATE_270)</span>
<span class="fragment">>>> im.save("rotated_hopper_270.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/rotated_hopper_270.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #16 Relative resize image with contain</p>
<pre class="fragment">
<code>
>>> from PIL import ImageOps
<span class="fragment">>>> ImageOps.contain(im, (100, 150)).save(</span>
<span class="fragment">>>> "contained_hopper.png")</span>
<span class="fragment">$ file contained_hopper.png</span>
<span class="fragment">contained_hopper.png: PNG image data,
100 x 100, 8-bit/color RGB, non-interlaced</span>
</code>
</pre>
<img class="fragment" src="img/contained_hopper.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #17 Relative resize image with cover</p>
<pre class="fragment">
<code>
>>> from PIL import ImageOps
<span class="fragment">>>> ImageOps.cover(im, (100, 150)).save("covered_hopper.png")</span>
<span class="fragment">$ file covered_hopper.png</span>
<span class="fragment">covered_hopper.png: PNG image data,
150 x 150, 8-bit/color RGB, non-interlaced</span>
</code>
</pre>
<img class="fragment" src="img/covered_hopper.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #18 Relative resize image with fit</p>
<pre class="fragment">
<code>
>>> from PIL import ImageOps
<span class="fragment">>>> ImageOps.fit(im, (100, 150)).save("fitted_hopper.png")</span>
<span class="fragment">$ file fitted_hopper.png</span>
<span class="fragment">fitted_hopper.png: PNG image data,
100 x 150, 8-bit/color RGB, non-interlaced</span>
</code>
</pre>
<img class="fragment" src="img/fitted_hopper.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #19 Relative resize image with pad</p>
<pre class="fragment">
<code>
>>> from PIL import ImageOps
<span class="fragment">>>> ImageOps.pad(im, (100, 150), color="#f00").save("padded_hopper.png")</span>
<span class="fragment">$ file padded_hopper.png</span>
<span class="fragment">padded_hopper.png: PNG image data,
100 x 150, 8-bit/color RGB, non-interlaced</span>
</code>
</pre>
<img class="fragment" src="img/padded_hopper.png">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #20 Convert mode</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = Image.open("hopper.ppm")</span>
<span class="fragment">>>> im = im.convert("L")</span>
<span class="fragment">>>> im.save("converted_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/converted_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #21 Image enhancement</p>
<pre class="fragment">
<code>
>>> from PIL import ImageFilter
<span class="fragment">>>> im = im.filter(ImageFilter.DETAIL)</span>
<span class="fragment">>>> im.save("enhanced_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/enhanced_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #22 Point operations</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> im = im.point(lambda i: i * 20)</span>
<span class="fragment">>>> im.save("transformed_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/transformed_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #23 Process bands</p>
<pre class="fragment">
<code>
>>> from PIL import Image
<span class="fragment">>>> source = im.split()</span>
<span class="fragment">>>> r, g, b = 0, 1, 2</span>
<span class="fragment">>>> mask = source[r].point(lambda i: i < 100 and 255)</span>
<span class="fragment">>>> out = source[g].point(lambda i: i * 0.7)</span>
<span class="fragment">>>> source[g].paste(out, None, mask)</span>
<span class="fragment">>>> im = Image.merge(im.mode, source)</span>
<span class="fragment">>>> im.save("masked_hopper.jpg")</span>
<span class="fragment">>>> print("Saved masked hopper!")</span>
</code>
</pre>
<img class="fragment" src="img/masked_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #24 Enhance image</p>
<pre class="fragment">
<code>
>>> from PIL import ImageEnhance
<span class="fragment">>>> im = ImageEnhance.Contrast(im)</span>
<span class="fragment">>>> im = im.enhance(1.3)</span>
<span class="fragment">>>> im.save("contrasted_hopper.jpg")</span>
<span class="fragment">>>> im.show()</span>
</code>
</pre>
<img class="fragment" src="img/contrasted_hopper.jpg">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #25 Image sequences</p>
<pre class="fragment">
<code>
>>> from PIL import ImageSequence
<span class="fragment">>>> im = Image.open("snorkle.gif")</span>
<span class="fragment">>>> i = 1</span>
<span class="fragment">>>> for frame in ImageSequence.Iterator(im):</span>
<span class="fragment">>>> frame.save(f"snorkle_{i}.png")</span>
<span class="fragment">>>> print(f"Saved snorkle frame {i}!")</span>
<span class="fragment">>>> i += 1</span>
</code>
</pre>
<img class="fragment" src="img/snorkle.gif">
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #26 Postscript</p>
<pre class="fragment">
<code>
>>> from PIL import PSDraw
<span class="fragment">>>> title = "hopper"</span>
<span class="fragment">>>> fp = open("postscript_hopper.ps", "wb")</span>
<span class="fragment">>>> ps = PSDraw.PSDraw(fp)</span>
<span class="fragment">>>> ps.begin_document(title)</span>
<span class="fragment">>>> ps.image((0, 0, 128, 128), im, 0)</span>
<span class="fragment">>>> ps.setfont("HelveticaNarrow-Bold", 36)</span>
<span class="fragment">>>> ps.text((0, 0), title)</span>
<span class="fragment">>>> ps.end_document()</span>
<span class="fragment">>>> print("Saved postscript hopper!")</span>
<span class="fragment">convert postscript_hopper.ps postscript_hopper.pdf</span>
</code>
</pre>
</section>
<!------------------------------------------------------------------------------->
<section>
<p>Example #26 Postscript</p>
<img class="fragment" src="img/screenshot7.png">
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>More on reading images</h3>
<p class="fragment">Example #27: Reading from an open file</p>
<pre class="fragment">
<code>
>>> with open("hopper.ppm", "rb") as fp:
<span class="fragment">>>> im = Image.open(fp)</span>
<span class="fragment">>>> print(im)</span>
<span class="fragment"><PIL.PpmImagePlugin.PpmImageFile image
mode=RGB size=128x128 at 0x1055FD940></span>
</code>
</pre>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>More on reading images</h3>
<p class="fragment">Example #28: Reading from binary data</p>
<pre class="fragment">
<code>
>>> buffer = read_image_to_buffer("hopper.ppm")
<span class="fragment">>>> print(type(buffer))</span>
<span class="fragment"><class '_io.BytesIO'></span>
<span class="fragment">>>> im = read_image_from_buffer(buffer)</span>
<span class="fragment">>>> print(im)</span>
<span class="fragment"><PIL.PpmImagePlugin.PpmImageFile image
mode=RGB size=128x128 at 0x1058294C0></span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>More on reading images</h3>
<p class="fragment">Example #29: Batch processing</p>
<pre class="fragment">
<code>
>>> import glob
>>> paths = glob.glob("*.png")
<span class="fragment">>>> for path in paths:</span>
<span class="fragment">>>> image = os.path.join(</span>
<span class="fragment">>>> "batch",</span>
<span class="fragment"> "".join([path[:-4], ".jpg"])</span>
<span class="fragment"> )</span>
<span class="fragment">>>> compress_image(path, image)</span>
<span class="fragment">img/batch/covered_hopper.jpg</span>
<span class="fragment">img/batch/screenshot.jpg</span>
<span class="fragment">img/batch/pillow-logo-light-text.jpg</span>
<span class="fragment">…</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>More on reading images</h3>
<p class="fragment">Example #29: Batch processing with pathlib</p>
<pre class="fragment">
<code>
>>> from pathlib import Path
>>> paths = Path(".").glob("*.png")
<span class="fragment">>>> for path in paths:</span>
<span class="fragment">>>> image = os.path.join(</span>
<span class="fragment">>>> "batch",</span>
<span class="fragment"> "".join([path.stem, ".jpg"])</span>
<span class="fragment"> )</span>
<span class="fragment">>>> compress_image(path, image)</span>
<span class="fragment">img/batch/covered_hopper.jpg</span>
<span class="fragment">img/batch/screenshot.jpg</span>
<span class="fragment">img/batch/pillow-logo-light-text.jpg</span>
<span class="fragment">…</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>More on reading images</h3>
<p class="fragment">Example #29: Batch processing output</p>
<pre class="fragment">
<code>
$ ls -1 img/batch<span class="fragment">
contained_hopper.jpg
covered_hopper.jpg
dcpython-logo.jpg
fitted_hopper.jpg
logo.jpg
logo_fancy.jpg
merged_hopper.jpg
merged_resized_hopper.jpg
padded_hopper.jpg
pillow-logo-light-text.jpg
screenshot.jpg
screenshot0.jpg
screenshot1.jpg
screenshot2.jpg
screenshot3.jpg
screenshot4.jpg
screenshot5.jpg
screenshot6.jpg
screenshot7.jpg
snorkle_1.jpg
snorkle_2.jpg
snorkle_3.jpg
</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Controlling the decoder</h3>
<p class="fragment">Example #30: Reading in draft mode</p>
<pre class="fragment">
<code>
>>> with Image.open("hopper.jpg") as im:
<span class="fragment">>>> print("original =", im.mode, im.size)</span>
<span class="fragment">>>> im.draft("L", (100, 100))</span>
<span class="fragment">>>> print("draft =", im.mode, im.size)</span>
<span class="fragment">original = RGB (128, 128)</span>
<span class="fragment">draft = L (128, 128)</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Also check out</h3>
<ul>
<li class="fragment">
<a target="_blank"
href="https://pillow.readthedocs.io/en/stable/handbook/concepts.html">https://pillow.readthedocs.io/en/stable/handbook/concepts.html</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://pillow.readthedocs.io/en/stable/handbook/appendices.html">https://pillow.readthedocs.io/en/stable/handbook/appendices.html</a>
</li>
<li class="fragment">
<a target="_blank"
href="https://github.com/python-pillow/Pillow/issues/1888">https://github.com/python-pillow/Pillow/issues/1888</a>
</li>
</ul>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #31: Bands</p>
<pre class="fragment">
<code>
>>> im = Image.open(os.path.join("img", "hopper.ppm"))
<span class="fragment">>>> print(im.getbands())</span>
<span class="fragment">('R', 'G', 'B')</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #32: Modes</p>
<pre class="fragment">
<code>
>>> im = Image.open(os.path.join("img", "hopper.ppm"))
<span class="fragment">>>> print(im.mode)</span>
<span class="fragment">RGB</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #33: Size</p>
<pre class="fragment">
<code>
>>> im = Image.open(os.path.join("img", "hopper.ppm"))
<span class="fragment">>>> print(im.size)</span>
<span class="fragment">(128, 128)</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #34: Coordinate System</p>
<pre class="fragment">
<code>
>>> import cart
<span class="fragment">Example #34: Writing coordinate_system_example.png!</span>
</code>
</pre>
<img class="fragment" src="img/coordinate_system_example.png" width="33%">
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #35: Palette</p>
<pre class="fragment">
<code>
>>> import pal
<span class="fragment">Example #35: Writing output_image_with_random_palette.png</span>
</code>
</pre>
<img class="fragment" src="img/output_image_with_random_palette.png">
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #36: Info</p>
<pre class="fragment">
<code>
>>> im = Image.open(os.path.join("img", "hopper.ppm"))
<span class="fragment">>>> print(im.info)</span>
<span class="fragment">{}</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #36: Info</p>
<pre class="fragment">
<code>
>>> im = Image.open(os.path.join("img", "alex-pillow.jpg"))
<span class="fragment">>>> print(im.info)</span>
<span class="fragment">{'icc_profile': b'\x00\x00…'
…
b'\x00\x00…',
'jfif': 257,
'jfif_density': (1, 1),
'jfif_unit': 0,
'jfif_version': (1, 1),
'progression': 1,
'progressive': 1}
</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #37: Transparency</p>
<pre class="fragment">
<code>
import alpha
<span class="fragment">Example #37: Writing transparent_image.png!</span>
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #38: Orientation</p>
<pre class="fragment">
<code>
raise NotImplementedError
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Concepts</h3>
<p class="fragment">Example #39: Filters</p>
<pre class="fragment">
<code>
raise NotImplementedError
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Logos</h3>
<p class="fragment">Example #40: Logo</p>
<pre class="fragment">
<code>
import logo
<span class="fragment">Example #40: Writing logo.png!</span>
</code>
</pre>
<img class="fragment" src="img/logo.png">
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>Logos</h3>
<p class="fragment">Example #41: Fancy Logo</p>
<pre class="fragment">
<code>
import logo_fancy
<span class="fragment">Example #41: Writing logo_fancy.png!</span>
</code>
</pre>
<img class="fragment" src="img/logo_fancy.png">
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h3>1888</h3>
<pre class="fragment">
<code>
raise NotImplementedError
</code>
</pre>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
<section data-background-color="aquamarine">
<h4>Thank you! 👋</h4>
<pre class="fragment">
Alex
---
Jeffrey "Alex" Clark
Python Pillow Creator
ACLARK.NET, LLC President
DC Python Executive Director
Let's Pay the Maintainers ✨
--------------------------------
aclark@aclark.net
</pre>
<ul>
<li class="fragment">
<a target="_blank"
href="https://github.com/python-pillow/pillow-dcpython">https://github.com/python-pillow/pillow-demo</a>
</li>
</ul>
<aside class="notes">
</aside>
</section>
<!------------------------------------------------------------------------------->
</div>
<script src="dist/bundle.js"></script> <!-- Make sure this path matches your webpack output -->
</body>
</html>