Merge pull request #1514 from fetlife/use-default-orientation-value-if-orientation-is-incorrect

Reset orientation if exif data is incorrect
This commit is contained in:
John Cupitt 2020-01-06 11:41:48 +00:00 committed by GitHub
commit 7732bf9981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -525,7 +525,8 @@ vips__exif_parse( VipsImage *image )
int orientation;
orientation = atoi( str );
orientation = VIPS_CLIP( 1, orientation, 8 );
if( orientation < 1 || orientation > 8 )
orientation = 1;
vips_image_set_int( image, VIPS_META_ORIENTATION, orientation );
}

View File

@ -189,6 +189,18 @@ class TestForeign:
assert x1.width == x2.height
assert x1.height == x2.width
# sets incorrect orientation, save, load again, orientation
# has reset to 1
x = x.copy()
x.set("orientation", 256)
filename = temp_filename(self.tempdir, '.jpg')
x.write_to_file(filename)
x = pyvips.Image.new_from_file(filename)
y = x.get("orientation")
assert y == 1
# can set, save and reload ASCII string fields
x = pyvips.Image.new_from_file(JPEG_FILE)
x = x.copy()