mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 18:07:51 +03:00 
			
		
		
		
	Removed DPI rounding from JPEG loading
This commit is contained in:
		
							parent
							
								
									0de3beaeaf
								
							
						
					
					
						commit
						18e204df05
					
				
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 20 KiB  | 
| 
						 | 
				
			
			@ -656,15 +656,6 @@ class TestFileJpeg:
 | 
			
		|||
                reloaded.load()
 | 
			
		||||
                assert im.info["dpi"] == reloaded.info["dpi"]
 | 
			
		||||
 | 
			
		||||
    def test_load_dpi_rounding(self):
 | 
			
		||||
        # Round up
 | 
			
		||||
        with Image.open("Tests/images/iptc_roundUp.jpg") as im:
 | 
			
		||||
            assert im.info["dpi"] == (44, 44)
 | 
			
		||||
 | 
			
		||||
        # Round down
 | 
			
		||||
        with Image.open("Tests/images/iptc_roundDown.jpg") as im:
 | 
			
		||||
            assert im.info["dpi"] == (2, 2)
 | 
			
		||||
 | 
			
		||||
    def test_save_dpi_rounding(self, tmp_path):
 | 
			
		||||
        outfile = str(tmp_path / "temp.jpg")
 | 
			
		||||
        with Image.open("Tests/images/hopper.jpg") as im:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,6 +33,7 @@
 | 
			
		|||
#
 | 
			
		||||
import array
 | 
			
		||||
import io
 | 
			
		||||
import math
 | 
			
		||||
import os
 | 
			
		||||
import struct
 | 
			
		||||
import subprocess
 | 
			
		||||
| 
						 | 
				
			
			@ -162,15 +163,17 @@ def APP(self, marker):
 | 
			
		|||
                dpi = float(x_resolution[0]) / x_resolution[1]
 | 
			
		||||
            except TypeError:
 | 
			
		||||
                dpi = x_resolution
 | 
			
		||||
            if math.isnan(dpi):
 | 
			
		||||
                raise ValueError
 | 
			
		||||
            if resolution_unit == 3:  # cm
 | 
			
		||||
                # 1 dpcm = 2.54 dpi
 | 
			
		||||
                dpi *= 2.54
 | 
			
		||||
            self.info["dpi"] = int(dpi + 0.5), int(dpi + 0.5)
 | 
			
		||||
            self.info["dpi"] = dpi, dpi
 | 
			
		||||
        except (KeyError, SyntaxError, ValueError, ZeroDivisionError):
 | 
			
		||||
            # SyntaxError for invalid/unreadable EXIF
 | 
			
		||||
            # KeyError for dpi not included
 | 
			
		||||
            # ZeroDivisionError for invalid dpi rational value
 | 
			
		||||
            # ValueError for x_resolution[0] being an invalid float
 | 
			
		||||
            # ValueError for dpi being an invalid float
 | 
			
		||||
            self.info["dpi"] = 72, 72
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user