Jump to content

Extract JPEG's from arbitrary file


Metzen

Recommended Posts

Hi,

 

I'm trying to use PHP to extract an arbitrary number of JPEG's from an arbitrary binary file.

 

This program is able to do it on windows:

http://schmidt.devlib.org/software/jpeg-extractor.html

 

$entire_file = file_get_contents("N38112G6.TPQ");

preg_match_all("/\xFF\xD8\xFF(.*)\xFF\xD9/s", $entire_file, $matches);

 

Then $matches[0][0] should contain the first JPEG (minus the first 3 bytes, FF D8 FF, and last 2 bytes, FF D9, which would be added before saving to a file).

 

Why isn't the above working?  Or is there a better approach altogether?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/39228-extract-jpegs-from-arbitrary-file/
Share on other sites

It's a binary file, but other than that it shouldn't matter.

 

I just want to search for and grab everything between the first 3 bytes that every JPEG starts with and the last 2 bytes it always ends with (Everything between "ff d8 ff" and  "ff d9").

 

That is exactly what the linked windows program does and it works beautifully, without knowing anything about the file.

 

For the curious, the files are part of National Geographic Topo! and contain 50 JPEG tiles that make up a quad of a topo map.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.