Repository: python-pillow/Pillow

Issue:
im.show: AttributeError: 'int' object has no attribute 'write'
### What did you do?

`im.show()` on Mac.

### What did you expect to happen?

It to show the image in Preview.app.

### What actually happened?

```
Traceback (most recent call last):
  File "1.py", line 3, in <module>
    im.show()
  File "/Users/hugo/github/Pillow/src/PIL/Image.py", line 2035, in show
    _show(self, title=title, command=command)
  File "/Users/hugo/github/Pillow/src/PIL/Image.py", line 2900, in _show
    _showxv(image, **options)
  File "/Users/hugo/github/Pillow/src/PIL/Image.py", line 2905, in _showxv
    ImageShow.show(image, title, **options)
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 53, in show
    if viewer.show(image, title=title, **options):
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 77, in show
    return self.show_image(image, **options)
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 97, in show_image
    return self.show_file(self.save_image(image), **options)
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 136, in show_file
    f.write(file)
AttributeError: 'int' object has no attribute 'write'
```

### What are your OS, Python and Pillow versions?

* OS: macOS High Sierra
* Python: 3.7.1 and 2.7.15
* Pillow: master

```python
from PIL import Image
im = Image.new("RGB", (200, 100))
im.show()
```

Cannot reproduce with last Pillow release 5.3.0.


Discussion:
git bisect points to fea3dafd05c8ca44c30167c34ce4d82964421efb from https://github.com/python-pillow/Pillow/pull/3450.


1.sh:
```sh
python3 setup.py clean
make clean
python3 setup.py develop
python3 1.py
```

1.py:
```python
from PIL import Image
im = Image.new("RGB", (200, 100))
im.show()
```

```sh
git bisect start
git bisect good 5.3.0
git bisect bad master
git bisect run sh 1.sh
```


```
Finished processing dependencies for Pillow==5.4.0.dev0
fea3dafd05c8ca44c30167c34ce4d82964421efb is the first bad commit
commit fea3dafd05c8ca44c30167c34ce4d82964421efb
Date:   Sat Nov 3 14:24:10 2018 +1100

    Supply filename through stdin instead of inline in Mac and Unix ImageShow viewers

:040000 040000 8b9b5c67f53dcc6a67c3d370aa98a022d3a710d8 db2ec6e164b854dc0f30e72f7816a5dccc741aa8 M	src
bisect run success
```
https://github.com/python-pillow/Pillow/blob/37d61f1e9b10055ea0f7f157228809dc9fb852a2/src/PIL/ImageShow.py#L133-L146

`f, path = tempfile.mkstemp()`

returns:

`3 /var/folders/kt/j77sf4_n6fnbx6pg199rbx700000gn/T/tmp_cn1hw21`



Resolving patch:
diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py
--- a/src/PIL/ImageShow.py
+++ b/src/PIL/ImageShow.py
@@ -132,9 +132,9 @@ def get_command(self, file, **options):
 
         def show_file(self, file, **options):
             """Display given file"""
-            f, path = tempfile.mkstemp()
-            f.write(file)
-            f.close()
+            fd, path = tempfile.mkstemp()
+            with os.fdopen(fd, 'w') as f:
+                f.write(file)
             with open(path, "r") as f:
                 subprocess.Popen([
                     'im=$(cat);'
@@ -171,9 +171,9 @@ def get_command(self, file, **options):
 
         def show_file(self, file, **options):
             """Display given file"""
-            f, path = tempfile.mkstemp()
-            f.write(file)
-            f.close()
+            fd, path = tempfile.mkstemp()
+            with os.fdopen(fd, 'w') as f:
+                f.write(file)
             with open(path, "r") as f:
                 command = self.get_command_ex(file, **options)[0]
                 subprocess.Popen([


Test patch: