Skip to content

Commit

Permalink
Fix RAW images file type detection
Browse files Browse the repository at this point in the history
For Sony and Canon Raw file formats. They are based on the tiff format
and have the same magic number data so they are incorrectly classified
as tiff images.

Defining them as subtypes of tiff solves this issue:

```ruby
Marcel::MimeType.for Pathname.new("/Users/afcapel/Downloads/RAW_SONY_ILCE-7M2.ARW"), name: "/Users/afcapel/Downloads/RAW_SONY_ILCE-7M2.ARW"
=> "image/x-raw-sony"
```
  • Loading branch information
afcapel authored and jeremy committed Mar 1, 2024
1 parent ccd4be5 commit 415a693
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/marcel/mime_type/definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
Marcel::MimeType.extend "image/heif", magic: [[4, "ftypmif1"]], extensions: %w( heif )
Marcel::MimeType.extend "image/heic", magic: [[4, "ftypheic"]], extensions: %w( heic )

Marcel::MimeType.extend "image/x-raw-sony", extensions: %w( arw ), parents: "image/tiff"
Marcel::MimeType.extend "image/x-raw-canon", extensions: %w( cr2 crw ), parents: "image/tiff"

Marcel::MimeType.extend "video/mp4", magic: [[4, "ftypisom"], [4, "ftypM4V "]], extensions: %w( mp4 m4v )

Marcel::MimeType.extend "audio/flac", magic: [[0, 'fLaC']], extensions: %w( flac ), parents: "audio/x-flac"
Expand Down
Binary file added test/fixtures/name/image/x-raw-canon/cr2.cr2
Binary file not shown.
Binary file added test/fixtures/name/image/x-raw-sony/arw.arw
Binary file not shown.

0 comments on commit 415a693

Please sign in to comment.