Welcome Guest, Not a member yet? Register   Sign In
EXIF data
#1

[eluser]Ignacio[/eluser]
How can I do for save EXIF data from an image?

It could be really useful using it with:

$data = $this->upload->data();

to:

$exif = $this->upload->exif();

and:

$exif['exif_device_model']; //Return ie: "iPhone"
$exif['exif_device_make']; //Return ie: "Apple"
$exif['exif_profile_name']; //Return ie: "Camera RGB Profile"
...
...
...


Is there something like this? Is correct using EXIF data right this?

I'm trying this stuff using this:

Code:
$exif = exif_read_data($data['full_path'], 0, true);
echo $data['full_path'].":<br />\n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}

return:

Code:
FILE.FileName: 232205172263e659ddea7119b601c152.jpg
FILE.FileDateTime: 1208193826
FILE.FileSize: 18765
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, EXIF
COMPUTED.html: width="240" height="180"
COMPUTED.Height: 180
COMPUTED.Width: 240
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.ApertureFNumber: f/2.8
IFD0.Make: Apple
IFD0.Model: iPhone
IFD0.Orientation: 1
IFD0.ResolutionUnit: 2
IFD0.DateTime: 2007:12:01 19:20:46
IFD0.Exif_IFD_Pointer: 119
EXIF.FNumber: 14/5
EXIF.DateTimeOriginal: 2007:12:01 19:20:46
EXIF.DateTimeDigitized: 2007:12:01 19:20:46
EXIF.ColorSpace: 1
EXIF.ExifImageWidth: 1280
EXIF.ExifImageLength: 960
EXIF.UndefinedTag:0xA500: 11/5

This is what I want, but I need a CI class to handle all the data. Ideas?

Thanks.
#2

[eluser]nmweb[/eluser]
Is there not a PEAR class to handle EXIF?
#3

[eluser]Ignacio[/eluser]
you mean this one? ExifTool
#4

[eluser]Ignacio[/eluser]
Ok, this is my hacked upload library for getting exif data with exiftool. Check this file.

This was really really hard to code, so, I don't know if is good, and is not 100% tested.

This fix the problem when you're uploading images with a Flash system, check this: http://ellislab.com/forums/viewthread/70979/.

First of all, I added a new var.
Code:
var $tags = "";

After that we're going to call a function for putting an array with all exif tags.
Code:
$this->tags = $this->get_exiftags($_FILES[$field]['tmp_name']);

Now look this part:
Code:
$this->file_type = $this->set_filetype();
This is really weird, right? I'm getting the filetype with exiftool, so, if you're uploading an image with a flash system (ie. application/octet-stream), you no need to worry about the mimetype, because perl return the REAL mimetype of the image. (Note: this only work with images and all the mimetypes is supporting by exiftool). I don't know if this is secure, but it works great.

What is the get_exiftags() function?
Code:
function get_exiftags($filename)
{
    $output = shell_exec("perl ".APPPATH."perl/exif_config.pl ".$filename."");
    $output = json_decode($output);
    
    $array = array();
    foreach($output as $key => $value){
        $array[$key] = $value;
    }

    return $array;
}

I did it with Exiftool (perl). Check my exif_config.pl file
Code:
#!/usr/bin/perl -s
use JSON;
use Image::ExifTool qw(:Public);
my $exifTool = new Image::ExifTool;

$filename = shift @ARGV;

$exifTool->Options(Duplicates => 0, Unknown => 1);
$info = $exifTool->ImageInfo($filename,
            'Mimetype',
            'Make',
            'Model',
            'Orientation',
            'Exposure',
            'Aperture',
            'Flash',
            'ColorSpace',
            'FocalLength',
            'XResolution',
            'YResolution',
            'FNumber',
            'ImageWidth',
            'ImageHeight',
            'LightSource',
            'Lens',
            'DigitalZoomRatio',
            'Lens',
            'ISO',
            'ExposureCompensation',
            'Gamma',
            'Transformation',
            'SceneCaptureType',
            'GainControl',
            'Contrast',
            'Saturation',
            'Sharpness',
            'DateTimeOriginal',
            'MeteringMode',
            'UserComment',
            'CreateDate',
            'ShutterSpeedValue',
            'WhiteBalance',
            'ExposureMode',
            'MaxApertureValue'
        );

$json_text = to_json($info);
print $json_text;

Yeah! Perl gives me and json array! awesome! So I can handle the data easily. Note: you can change this file watching this.

Now check this new and changed functions
Code:
function data()
{
    return array (
                    'file_name'    => $this->file_name,
                    'file_type'    => $this->set_filetype(),
                    'file_path'    => $this->upload_path,
                    'full_path' => $this->upload_path.$this->file_name,
                    'raw_name' => str_replace($this->file_ext, '', $this->file_name),
                    'orig_name' => $this->orig_name,
                    'file_ext' => $this->file_ext,
                    'file_size' => $this->file_size,
                    'is_image' => $this->is_image(),
                    'image_width' => $this->image_width,
                    'image_height' => $this->image_height,
                    'image_type' => $this->image_type,
                    'image_size_str' => $this->image_size_str,
                    'date_original' => $this->set_date_original(),
                    'date_taken' => $this->set_date_taken(),
                    'exiftags' => $this->tags
                );
}


function set_filetype()
{
    return @$this->tags['MIMEType'];
}

function set_date_original()
{
    return @$this->tags['DateTimeOriginal'];
}

function set_date_taken()
{
    return @$this->tags['CreateDate'];
}

If you look carefully, you'll note that I added more items for upload->data, like:

date_original
date_taken
exiftags: this is awesome! all the entire array! I can save all the info in my bd.

I steal this idea from flickr, ;-P

Sorry about my english and bad explanation, but I'm happy with this, it took me sometime coding this.
#5

[eluser]Ignacio[/eluser]
Oh, I forgot one thing, the script has a function for splitting the files into two folders.
#6

[eluser]Hermawan Haryanto[/eluser]
I think you should post this thread to the forum Ignited Code




Theme © iAndrew 2016 - Forum software by © MyBB