Welcome Guest, Not a member yet? Register   Sign In
EXIF data
#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.


Messages In This Thread
EXIF data - by El Forum - 04-14-2008, 11:22 AM
EXIF data - by El Forum - 04-14-2008, 12:42 PM
EXIF data - by El Forum - 04-14-2008, 01:10 PM
EXIF data - by El Forum - 05-02-2008, 01:34 PM
EXIF data - by El Forum - 05-02-2008, 02:29 PM
EXIF data - by El Forum - 05-03-2008, 11:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB