
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
is a Ruby library for prying open video, image, document, and audio files. It includes a number of parser modules that try to recover metadata useful for post-processing and layout while reading the absolute minimum amount of data possible.
format_parser is inspired by imagesize, fastimage
and dimensions, borrowing from them where appropriate.
...with more on the way!
Pass an IO object that responds to read, seek and size to FormatParser.parse and the first confirmed match will be returned.
match = FormatParser.parse(File.open("myimage.jpg", "rb"))
match.nature #=> :image
match.format #=> :jpg
match.display_width_px #=> 320
match.display_height_px #=> 240
match.orientation #=> :top_left
You can also use parse_http passing a URL or parse_file_at passing a path:
match = FormatParser.parse_http('https://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg')
match.nature #=> :image
match.format #=> :jpg
If you would rather receive all potential results from the gem, call the gem as follows:
array_of_results = FormatParser.parse(File.open("myimage.jpg", "rb"), results: :all)
You can also optimize the metadata extraction by providing hints to the gem:
FormatParser.parse(File.open("myimage", "rb"), natures: [:video, :image], formats: [:jpg, :png, :mp4], results: :all)
Return values of all parsers have built-in JSON serialization
img_info = FormatParser.parse(File.open("myimage.jpg", "rb"))
JSON.pretty_generate(img_info) #=> ...
To convert the result to a Hash or a structure suitable for JSON serialization
img_info = FormatParser.parse(File.open("myimage.jpg", "rb"))
img_info.as_json
# it's also possible to convert all keys to string
img_info.as_json(stringify_keys: true)
See the section on writing parsers in CONTRIBUTING.md
We need to recover metadata from various file types, and we need to do so satisfying the following constraints:
Therefore we adapt the following approaches:
Range: headers, GZIP compression and the likeWe are incredibly grateful to Remco van't Veer for exifr and to Krists Ozols for id3tag that we are using for crucial tasks.
Unless specified otherwise in this section the fixture files are MIT licensed and from the FastImage and Dimensions projects.
divergent_pixel_dimensions_exif.jpg is used with permission from LiveKom GmbHextended_reads.jpg has kindly been made available by Raphaelle Pellerin for use exclusively with format_parsertoo_many_APP1_markers_surrogate.jpg was created by the project maintainersorient_6.jpg is used with permission from Renaud Chaputkeynote_recognized_as_jpeg.key file was created by the project maintainershi.ogg, vorbis.ogg, with_confusing_magic_string.ogg, invalid_with_garbage_at_the_end.ogg have been generated by the project contributorssimulator_screenie.png provided by Rens VerhoevenShinbutsureijoushuincho.tiff is obtained from Wikimedia Commons and is Creative Commons licensedIMG_9266_*.tif and all it's variations were created by the project maintainersCopyright (c) 2020 WeTransfer.
format_parser is distributed under the conditions of the Hippocratic License
FAQs
Unknown package
We found that format_parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.