This repository was archived by the owner on Dec 7, 2021. It is now read-only.
fix: Use image/jpeg as MIME type for canvas.toBlob#801
Closed
mloenow wants to merge 1 commit intomicrosoft:masterfrom
Closed
fix: Use image/jpeg as MIME type for canvas.toBlob#801mloenow wants to merge 1 commit intomicrosoft:masterfrom
mloenow wants to merge 1 commit intomicrosoft:masterfrom
Conversation
The default MIME type for `canvas.toBlob(..)` is `image/png`[0], however, when exporting video assets (e.g. to the Pascal VOC format), the file extension is `.jpg` for each frame, resulting in a mismatch between extension and MIME type, which can cause issues in your data pipeline. Verified with `PIL` (`image = PIL.Image.open(encoded_image_io)`, `image.format`), and `exiftool` below: ``` $ exiftool /data/Test-PascalVOC-export/JPEGImages/IMG_4926.MOV#t=0.066667.jpg ExifTool Version Number : 11.30 File Name : IMG_4926.MOV#t=0.066667.jpg Directory : /data/Test-PascalVOC-export/JPEGImages File Size : 2.5 MB File Modification Date/Time : 2019:05:03 16:35:29+02:00 File Access Date/Time : 2019:05:03 18:19:43+02:00 File Inode Change Date/Time : 2019:05:03 16:35:29+02:00 File Permissions : rw-r--r-- File Type : PNG File Type Extension : png MIME Type : image/png Image Width : 1080 Image Height : 1440 Bit Depth : 8 Color Type : RGB with Alpha Compression : Deflate/Inflate Filter : Adaptive Interlace : Noninterlaced Image Size : 1080x1440 Megapixels : 1.6 ``` This pull request explicitly sets the MIME type to `image/jpeg` with full quality (1.0). [0] https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#Parameters
Codecov Report
@@ Coverage Diff @@
## master #801 +/- ##
======================================
Coverage 87.9% 87.9%
======================================
Files 129 129
Lines 4845 4845
Branches 922 922
======================================
Hits 4259 4259
Misses 584 584
Partials 2 2
Continue to review full report at Codecov.
|
Closed
wbreza
approved these changes
Aug 2, 2019
| const ctx = canvas.getContext("2d"); | ||
| ctx.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
| canvas.toBlob(resolve); | ||
| canvas.toBlob(resolve, "image/jpeg", 1.0); |
wbreza
suggested changes
Aug 2, 2019
Contributor
wbreza
left a comment
There was a problem hiding this comment.
Please re-target to the develop branch. Thanks!
mloenow
added a commit
to mloenow/VoTT
that referenced
this pull request
Aug 6, 2019
Retargeted. See microsoft#801. Closes microsoft#801, microsoft#838.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default MIME type for
canvas.toBlob(..)isimage/png[0], however, when exporting video assets (e.g. to the Pascal VOC format), the file extension is.jpgfor each frame, resulting in a mismatch between extension and MIME type, which can cause issues in your data pipeline.Verified with
PIL(image = PIL.Image.open(encoded_image_io),image.format), andexiftoolbelow:This pull request explicitly sets the MIME type to
image/jpegwith full quality (1.0).[0] https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#Parameters