Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3322674
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:12:36+00:00 2026-05-17T23:12:36+00:00

I would like to extract two fields from a PNG file. Namely, the geometry

  • 0

I would like to extract two fields from a PNG file. Namely, the geometry field and one of the fields from the metadata.

What is the fastest way I could go about doing this? I have benchmarked my script that currently performs this and by far the slowest action is executing the actual ImageMagick “identify” program on the PNG file. (.4 seconds vs .0001 seconds to parse the outputted array for the geometry and 8.39E-5 seconds to parse key phrases from the metadata)

Thanks in advance for any help,

Jonathan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:12:37+00:00Added an answer on May 17, 2026 at 11:12 pm

    I’m not familiar with any ready-made libraries or classes to do it in PHP without a subprocess call, but if you can’t find one, writing your own would definitely be the way to go.

    PNG’s a fairly simple block stream format, so seeking to a specific block and extracting some header fields is trivial.

    All you’d need is something which reads and checks the 8-byte 89 50 4E 47 0D 0A 1A 0A PNG header and then alternates between reading 8 bytes (chunk length plus type) and seeking past the block using the length until you hit the chunk type you want.

    For the geometry, assuming the PNG follows the spec, here’s how it’d go:

    1. Read and verify PNG header (8 bytes)
    2. Read and check header of first block (8 bytes)
      1. Success. type = IHDR
      2. Read additional 8 bytes for geometry (width, height. 4 bytes each)
    3. If the other field you wanted isn’t in IHDR, use the chunk size from step 2 to seek to the next block in search of the other field you wanted.

    It’d probably take me 5 to 15 minutes to whip something like that up in Python. (I’ve done similar things with RAR and GIF) Maybe 15 to 25 in PHP since I’ve got less experience doing low-level file I/O in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to extract some lines from a text file, I have started
I would like to extract items from this sample html, more specificly, i would
I would like to extract the GPS EXIF tag from pictures using php. I'm
I would like to extract a value or its inverse from database. I would
I would like to extract only tar.gz from the following strings. /root/abc/xzy/file_tar_src-5.2.8.23.tar.gz or /root/abc/xyz/file_tar_src-5.2.tar.gz
Hello! I would like to extract all citations from a text. Additionally, the name
I would like to extract some text between two points in a string, in
I would like to extract all text from subnodes of a specific document, AND
My XML file looks like this: <strings> <string>Bla <b>One &amp; Two</b> Foo</string> </strings> I
I have two .csv files containing correlation matrices exported from R. One file contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.