From 61d07849335715b978235ad452e89b56f30ad757 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Dec 2019 11:25:39 +1100 Subject: [PATCH 1/2] Allow loading of WMF images at a given DPI --- Tests/images/drawing_wmf_ref_144.png | Bin 0 -> 1209 bytes Tests/test_file_wmf.py | 11 +++++++++++ src/PIL/WmfImagePlugin.py | 22 +++++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 Tests/images/drawing_wmf_ref_144.png diff --git a/Tests/images/drawing_wmf_ref_144.png b/Tests/images/drawing_wmf_ref_144.png new file mode 100644 index 0000000000000000000000000000000000000000..20ed9ce597b5f648871c3210a4a560987f38ed61 GIT binary patch literal 1209 zcmeAS@N?(olHy`uVBq!ia0vp^OF)=|2}n-6E+odlz|!F9;uumf=k1-llO8DuI6Umz z`u_i^o7~Hie0V-xc5t3wygM}e$!s>+$2q_EasPaA{{?qI-fgqH{|lBT-Vm!WdUe46 z?7pzgN$w4z^ZlQ+XB;b?&AFTZ!{f#F|1axgTQGi`{PDo+x+e2|GnQ?9e}--SSHAo* zPu(Q{#G3Q_cIm$HoOwP{ZF^H~qFJGDY3voZqe4TNArjmT;UbD}Z%1_oS_G`_* z^!w7KqUxr*bx+GP52VD;*jrlmZqJXs>bG}p;gS7VH<|bI(tpbLGB-`!cfJ0|Y=5&e z_OHzz<*G}+oU*I8!uiePUDNB+L+@91-m2Vw$j&=BY3<(G3CgiC!TGg0OSH3}ukGpG z;?=vybmPRZHLcsF%r3oJS^YXe`L0H6K5NdB*~?zUcK4RFZ`reY!^C&fy2>rhF3ny2 zUGIonmB-Y3sy96N*QA|2y}fXWyJ*mf+)he_J)TKUeK`V1hMQj{Dvg=IXC~$+J&_R5L*Z8{cYdfT#xwKGJWm&P?7E z3)T-Z^6hWEIJGNZ@PJA?bLmZ?Ot&U9_B7&YPHER zD^`}h6sdG`^4YY!<#%ps*U#_$zM`oA)ncJHj}t$^YL9f5FBVzq`tftlo~xIqirt+p{vpgK zHtNdzkb}`n#V%cXv`uA?cD9Oc?>ooCyLXgby7aEic@KA%magx6J=-L?6u zcJb!-{O5)*d-+x|dj4$xZEyef?6~=Kg>> Date: Mon, 30 Dec 2019 10:12:37 +1100 Subject: [PATCH 2/2] Updated WMF documentation [ci skip] --- docs/handbook/image-file-formats.rst | 69 +++++++++++++++------------- docs/releasenotes/7.0.0.rst | 12 +++++ 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index 088fd5a0396..0e068c1e4eb 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -1019,6 +1019,43 @@ this format. By default, a Quake2 standard palette is attached to the texture. To override the palette, use the putpalette method. +WMF +^^^ + +Pillow can identify WMF files. + +On Windows, it can read WMF files. By default, it will load the image at 72 +dpi. To load it at another resolution: + +.. code-block:: python + + from PIL import Image + with Image.open("drawing.wmf") as im: + im.load(dpi=144) + +To add other read or write support, use +:py:func:`PIL.WmfImagePlugin.register_handler` to register a WMF handler. + +.. code-block:: python + + from PIL import Image + from PIL import WmfImagePlugin + + class WmfHandler: + def open(self, im): + ... + def load(self, im): + ... + return image + def save(self, im, fp, filename): + ... + + wmf_handler = WmfHandler() + + WmfImagePlugin.register_handler(wmf_handler) + + im = Image.open("sample.wmf") + XPM ^^^ @@ -1176,35 +1213,3 @@ MPEG ^^^^ Pillow identifies MPEG files. - -WMF -^^^ - -Pillow can identify playable WMF files. - -In PIL 1.1.4 and earlier, the WMF driver provides some limited rendering -support, but not enough to be useful for any real application. - -In PIL 1.1.5 and later, the WMF driver is a stub driver. To add WMF read or -write support to your application, use -:py:func:`PIL.WmfImagePlugin.register_handler` to register a WMF handler. - -:: - - from PIL import Image - from PIL import WmfImagePlugin - - class WmfHandler: - def open(self, im): - ... - def load(self, im): - ... - return image - def save(self, im, fp, filename): - ... - - wmf_handler = WmfHandler() - - WmfImagePlugin.register_handler(wmf_handler) - - im = Image.open("sample.wmf") diff --git a/docs/releasenotes/7.0.0.rst b/docs/releasenotes/7.0.0.rst index cf88dfa6495..9a4b5a42b35 100644 --- a/docs/releasenotes/7.0.0.rst +++ b/docs/releasenotes/7.0.0.rst @@ -94,6 +94,18 @@ Custom unidentified image error Pillow will now throw a custom ``UnidentifiedImageError`` when an image cannot be identified. For backwards compatibility, this will inherit from ``IOError``. +Loading WMF images at a given DPI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +On Windows, Pillow can read WMF files, with a default DPI of 72. An image can +now also be loaded at another resolution: + +.. code-block:: python + + from PIL import Image + with Image.open("drawing.wmf") as im: + im.load(dpi=144) + Other Changes =============