Repository: python-pillow/Pillow

Issue:
PlanarConfiguration save
### What did you do?
- Open a file using Pillow Image.open `im = Image.open(..blah)`
- downscale the image using Image.thumnail `im.thumbnail(..blah)`
   - (Args: (512, 512), Image.ANTIALIAS) 
- Save the image using save function, only passing new file name `im.save('file_two.tif/tiff')` - Same issue for tiff and tif.
### What did you expect to happen?
Image would be saved, scaled down, and viewable.

### What actually happened?
Image was downscaled, but corrupt, appears red and pixellated, cannot be opened in some image viewers.

Note: I cannot repeat this on Mac OS, haven't tried this on Debian... yet.

### What are your OS, Python and Pillow versions?
* OS: Windows 10 Version 10.0.17763 Build 17763
* Python:  Python 3.6.8 
* Pillow: Pillow 5.4.1

![Corrupted Image](https://github.com/VariableDeclared/Mask_RCNN/blob/5f9f89dbc55301cee09cac42ad06a8d8d7abe211/samples/datasets/xview_dataset/PILissue.tiff)
```python
from PIL import Image
import os


mode = input("Enter mode")

files = [f for f in os.listdir('./{}'.format(mode)) if os.path.isfile(os.path.join('./{}'.format(mode), f))]

im = Image.open('./{}/{}'.format(mode, files[0]))
im.show()

input()
im.thumbnail((512, 512), Image.ANTIALIAS)

im.save('./PILissue.tiff')
```


Discussion:
The PlanarConfiguration tag value is wrong. It should be CONTIG (but is SEPARATE). You can verify by patching the example file with a hex editor at position 126 from 2 to 1.
You've provided a copy of the output image. Are you able to provide a copy of one of the images that you are running this script over?
It seems any input image with PlanarConfiguration=2 will trigger this bug. 
Ok, thanks. On macOS 10.14, if I try to save https://github.com/python-pillow/Pillow/blob/master/Tests/images/tiff_tiled_planar_raw.tif I get a black image.

```python
im = Image.open('tiff_tiled_planar_raw.tif')
im.save('out.tif')
```

Presuming that this is the same issue, if you're interested in an immediate solution, I would recommend adding in `im._planar_configuration = 1` -

```python
from PIL import Image
import os


mode = input("Enter mode")

files = [f for f in os.listdir('./{}'.format(mode)) if os.path.isfile(os.path.join('./{}'.format(mode), f))]

im = Image.open('./{}/{}'.format(mode, files[0]))
im.show()

input()
im.thumbnail((512, 512), Image.ANTIALIAS)
im._planar_configuration = 1
im.save('./PILissue.tiff')
```

Resolving patch:
diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py
--- a/src/PIL/TiffImagePlugin.py
+++ b/src/PIL/TiffImagePlugin.py
@@ -1528,7 +1528,7 @@ def _save(im, fp, filename):
     libtiff = WRITE_LIBTIFF or compression != "raw"
 
     # required for color libtiff images
-    ifd[PLANAR_CONFIGURATION] = getattr(im, "_planar_configuration", 1)
+    ifd[PLANAR_CONFIGURATION] = 1
 
     ifd[IMAGEWIDTH] = im.size[0]
     ifd[IMAGELENGTH] = im.size[1]


Test patch:
diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py
--- a/Tests/test_file_tiff.py
+++ b/Tests/test_file_tiff.py
@@ -594,6 +594,17 @@ def test_tiled_planar_raw(self):
         with Image.open(infile) as im:
             assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
 
+    def test_planar_configuration_save(self, tmp_path):
+        infile = "Tests/images/tiff_tiled_planar_raw.tif"
+        with Image.open(infile) as im:
+            assert im._planar_configuration == 2
+
+            outfile = str(tmp_path / "temp.tif")
+            im.save(outfile)
+
+            with Image.open(outfile) as reloaded:
+                assert_image_equal_tofile(reloaded, infile)
+
     def test_palette(self, tmp_path):
         def roundtrip(mode):
             outfile = str(tmp_path / "temp.tif")