Slotty Bon
Slotty Bon

Reputation: 101

extract info from jpeg with PHP

I want to extract variable lengths of information from a jpeg-file using PHP, but it is not exif-data.

If I open the jpeg with a simple text editor, I can see that the wanted informations are at the end of the file and seperated by \00.

Like this:

\00DATA\00DATA00DATA\00DATA\000\00DATA

Now if I use PHP's file_get_contents() to load the file into a string, the dividers \00 are gone and other symbols show up. Like so:

ÿëžDATADATADATADATADATA ÿÙ

Could somebody please eplain:

EDIT

The question is solved, but for those seeking a smarter solution, here is the file I try to obtain the DATA parts from: https://www.dropbox.com/s/5cwnlh2kadvi6f7/test-img.jpg?dl=0 (yes I know its corrupted)

Upvotes: 4

Views: 355

Answers (2)

Slotty Bon
Slotty Bon

Reputation: 101

I came up with a solution on my own. May not be pretty, but works for me.

Using urlencode(file_get_contents()) I was able to retrieve the \00 parts as %00.

So now it reads like this:

%00DATA%00DATA%00DATA%00DATA%000%00DATA

I can split the string at the %00 parts.

I am going to accept this answer, once SO lets me do so and nobody comes up with a better solution.

Upvotes: 1

Armen
Armen

Reputation: 4192

Use instead $data = exif_read_data("PATH/some.jpg") it will give you all headers data about image, you can check its manual here - http://php.net/manual/en/function.exif-read-data.php

Upvotes: 2

Related Questions