Page MenuHomePhabricator

Thumbnails of multi-page TIF files only show a fragment of the 2nd page if it has a different size than the 1st page
Open, LowPublic

Description

Thumbnailing on large multi-page TIF-files works fine, but there is an issue with files where each page has a different size. See example. The first page is 8.973 × 6.724 px, the second 160 x 120 px. The thumbnailer seems to use the first page's size for the second page, too. In this case it dosn't matter, but there may exist files where it is disturbing.
This is the 2nd page of the file:


This is the generated thumbnail of the 2nd page:
thumbnail.jpg (128×160 px, 884 B)

Event Timeline

Logs from testing locally:

2021-02-16 02:36:43 thumbor:DEBUG METRICS: inc: response.count:1
2021-02-16 02:36:43 thumbor:DEBUG Format specified: jpg
2021-02-16 02:36:43 thumbor:DEBUG METRICS: inc: storage.miss:1
2021-02-16 02:36:43 thumbor:DEBUG [HTTPS] load_sync: https%3A//upload.wikimedia.org/wikipedia/commons/5/50/Bronx%2C_V._12%2C_Double_Page_Plate_No._262_%28Map_bounded_by_Clinton_Ave.%2C_E._180th_St.%2C_Honeywell_Ave.%2C_Southern_Blvd.%2C_Crotona_Park_North%29_NYPL2001520.tiff
2021-02-16 02:36:43 thumbor:DEBUG [HTTPS] Loading normalized URL: https://upload.wikimedia.org/wikipedia/commons/5/50/Bronx%2C_V._12%2C_Double_Page_Plate_No._262_%28Map_bounded_by_Clinton_Ave.%2C_E._180th_St.%2C_Honeywell_Ave.%2C_Southern_Blvd.%2C_Crotona_Park_North%29_NYPL2001520.tiff
2021-02-16 02:36:50 thumbor:DEBUG [HTTPS] return_contents: /tmp/tmpnYxNj6
2021-02-16 02:36:50 thumbor:DEBUG METRICS: inc: original_image.status.200:1
2021-02-16 02:36:50 thumbor:DEBUG METRICS: inc: original_image.response_bytes:4096
2021-02-16 02:36:50 thumbor:DEBUG [Proxy] Looking for a tiff engine
2021-02-16 02:36:50 thumbor:DEBUG [ExiftoolRunner] command: ['/usr/bin/exiftool', '-ImageSize', '-s', '-s', '-s', '/tmp/tmpnYxNj6']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Command: ['/usr/bin/timeout', '--foreground', '59', '/usr/bin/exiftool', '-ImageSize', '-s', '-s', '-s', '/tmp/tmpnYxNj6']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stdout: 8973x6724

2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stderr: 
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Return code: 0
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Duration: 165.047
2021-02-16 02:36:50 thumbor:DEBUG [VIPS] Shrinking with command
2021-02-16 02:36:50 thumbor:DEBUG [BWE] Found source file in context
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Command: ['/usr/bin/timeout', '--foreground', '59', '/usr/bin/vips', 'shrink', '/tmp/tmpnYxNj6[page=1]', '/tmp/tmpUcw8ES/vips_result.png', '28', '28']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stdout: 
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stderr: vips warning: tiff2vips: no resolution information for TIFF image "/tmp/tmpnYxNj6" -- defaulting to 1 pixel per mm
vips warning: tiff2vips: no resolution information for TIFF image "/tmp/tmpnYxNj6" -- defaulting to 1 pixel per mm

2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Return code: 0
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Duration: 133.23
2021-02-16 02:36:50 thumbor:DEBUG [IM] Dumping buffer into temp file
2021-02-16 02:36:50 thumbor:DEBUG [ExiftoolRunner] command: ['/usr/bin/exiftool', '-s', '-s', '-ImageSize', '-ProfileDescription', '-ColorType', '-FileType', '-Transparency', '-Artist', '-Copyright', '-ImageDescription', '/tmp/tmp28RDaA']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Command: ['/usr/bin/timeout', '--foreground', '59', '/usr/bin/exiftool', '-s', '-s', '-ImageSize', '-ProfileDescription', '-ColorType', '-FileType', '-Transparency', '-Artist', '-Copyright', '-ImageDescription', '/tmp/tmp28RDaA']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stdout: ImageSize: 5x4
ColorType: RGB
FileType: PNG

2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stderr: 
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Return code: 0
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Duration: 81.23700000000001
2021-02-16 02:36:50 thumbor:DEBUG [IM] EXIF: {'FileType': 'PNG', 'ColorType': 'RGB', 'ImageSize': '5x4'}
2021-02-16 02:36:50 thumbor:DEBUG [IM] File has no ICC profile
2021-02-16 02:36:50 thumbor:DEBUG [IM] reorientate
2021-02-16 02:36:50 thumbor:DEBUG [IM] resize: 160.0 128.0
2021-02-16 02:36:50 thumbor:DEBUG [IM] Queued operators: ['-resize', '160x128^', '-gravity', 'center', '-extent', '160x128']
2021-02-16 02:36:50 thumbor:DEBUG Image format specified as .jpg.
2021-02-16 02:36:50 thumbor:DEBUG Content Type of image/jpeg detected.
2021-02-16 02:36:50 thumbor:DEBUG [BWE] Rendering jpg
2021-02-16 02:36:50 thumbor:DEBUG [IM] read: jpg 87
2021-02-16 02:36:50 thumbor:DEBUG [IM] Chroma subsampling: '4:2:0'
2021-02-16 02:36:50 thumbor:DEBUG [IM] Generating image with quality 87
2021-02-16 02:36:50 thumbor:DEBUG [IM] Queued operators: ['-resize', '160x128^', '-gravity', 'center', '-extent', '160x128', '-quality', '87', '-sampling-factor', '4:2:0', '-interlace', 'Plane']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Command: ['/usr/bin/timeout', '--foreground', '59', '/usr/bin/convert', '-define', 'tiff:exif-properties=no', '-resize', '160x128^', '-gravity', 'center', '-extent', '160x128', '-quality', '87', '-sampling-factor', '4:2:0', '-interlace', 'Plane', '/tmp/tmp28RDaA[1]', u'jpg:-']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stdout: <too long to display (1168 bytes)>
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stderr: 
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Return code: 0
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Duration: 11.719
2021-02-16 02:36:50 thumbor:DEBUG [IM] Processing EXIF
2021-02-16 02:36:50 thumbor:DEBUG [ExiftoolRunner] command: ['/usr/bin/exiftool', '-m', '-all=', '/tmp/tmpRrTjru', '-o', '-']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Command: ['/usr/bin/timeout', '--foreground', '59', '/usr/bin/exiftool', '-m', '-all=', '/tmp/tmpRrTjru', '-o', '-']
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stdout: <too long to display (1150 bytes)>
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Stderr: 
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Return code: 0
2021-02-16 02:36:50 thumbor:DEBUG [ShellRunner] Duration: 107.61800000000001
2021-02-16 02:36:50 thumbor:DEBUG METRICS: timing: engine.processing_time.wikimedia_thumbor.engine.vips:544
2021-02-16 02:36:50 thumbor:DEBUG METRICS: timing: engine.processing_utime.wikimedia_thumbor.engine.vips:363
2021-02-16 02:36:50 tornado.access:INFO 200 GET /thumbor/unsafe/160x/filters:format(jpg):page(2)/https://upload.wikimedia.org/wikipedia/commons/5/50/Bronx%2C_V._12%2C_Double_Page_Plate_No._262_%28Map_bounded_by_Clinton_Ave.%2C_E._180th_St.%2C_Honeywell_Ave.%2C_Southern_Blvd.%2C_Crotona_Park_North%29_NYPL2001520.tiff (172.17.0.1) 6806.74ms
2021-02-16 02:36:50 thumbor:DEBUG METRICS: timing: response.time:6806
2021-02-16 02:36:50 thumbor:DEBUG METRICS: timing: response.time.200:6806
2021-02-16 02:36:50 thumbor:DEBUG METRICS: inc: response.status.200:1
2021-02-16 02:36:50 thumbor:DEBUG METRICS: inc: response.format.jpg:1
2021-02-16 02:36:50 thumbor:DEBUG METRICS: timing: response.time.jpg:6806
2021-02-16 02:36:50 thumbor:DEBUG METRICS: inc: response.bytes.jpg:1150
2021-02-16 02:37:10 thumbor:DEBUG [HTTPS] cleanup_temp_file: /tmp/tmpnYxNj6

One of the first things that is done is to run exiftool to figure out the original size of the thumbnail:

$ exiftool -ImageSize -s -s -s Bronx,_V._12,_Double_Page_Plate_No._262_\(Map_bounded_by_Clinton_Ave.,_E._180th_St.,_Honeywell_Ave.,_Southern_Blvd.,_Crotona_Park_North\)_NYPL2001520.tiff                                     
8973x6724

Exiftool calculates ImageSize based on the first IFD (page), ignoring all other directories (pages). For TIFFs, we'll have to get the height and width for the relevant IFD instead.