Metzen Posted February 19, 2007 Share Posted February 19, 2007 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 More sharing options...
printf Posted February 19, 2007 Share Posted February 19, 2007 What is the format of the N38112G6.TPQ file? Link to comment https://forums.phpfreaks.com/topic/39228-extract-jpegs-from-arbitrary-file/#findComment-189006 Share on other sites More sharing options...
Metzen Posted February 19, 2007 Author Share Posted February 19, 2007 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. Link to comment https://forums.phpfreaks.com/topic/39228-extract-jpegs-from-arbitrary-file/#findComment-189014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.