This topic is locked

Read image EXIF and save EXIF value to database

12/16/2014 9:22:00 PM
PHPRunner Tips and Tricks
romaldus author

This is a simple idea to read image EXIF and save exif value to database.

i have two tables: (Master Detail): picture_upload and exif_details
picture_id (integer 11, autoincrement),

picture_file ( varchar 400)
in phprunner, configure picture_file field to upload image
[color="#000080"]exif_details (detail table) :

detail_id (integer 11, autoincrement),

picture_id (integer 11 ), <--------link from master table

make (char 30),

camera_model (char 50),

date_taken (datetime),

image_width (integer 10),

image_height (integer 10),

f_number (char 10),

shutter_speed (char 10),

iso (char 10)
What i want to do here :

  1. (In master Table) Upload picture and value
  2. Read EXIF data from uploaded picture in master table and save exif value to detail table
    On [color="#0000FF"]before record added event of master table (picture_upload table), add the following code to rename uploaded picture (this is a sample code from phprunner manual)


$fileArray = my_json_decode($values["PICTURE_FILE"]);
// rename files
for($i = 0; $i < count($fileArray); $i++)
{
$fileName = $fileArray[$i]["name"];
//NOTE: myphotos/ is a folder where you save uploaded pictures
$newFileName = "myphotos/".$values["PICTURE_ID"].".jpg";
rename($fileName, getabspath($newFileName));
$fileArray[$i]["name"] = $newFileName;
}
// update values of the field that stores file names
$values["PICTURE_FILE"] = my_json_encode($fileArray);
return true;


On event of master table (picture_upload table), add the following code to read and save exif to database


$filename = "mypotos/".$values["PICTURE_ID"].".jpg";
if (file_exists($filename))
{
$exif = exif_read_data($filename, 0, true);
global $conn;
$strSQLInsert = "insert into exif_details
(
picture_id,
make ,
camera_model,
date_taken,
image_width,
image_height,
f_number,
shutter_speed,
iso
)
values
(
'".$values["PICTURE_ID"] ."',
'".$exif['IFD0']['Make']."',
'".$exif['IFD0']['Model']."',
'".$exif['EXIF']['DateTimeOriginal']."',
'".$exif['COMPUTED']['Width']."',
'".$exif['COMPUTED']['Height']."',
'".$exif['COMPUTED']['ApertureFNumber']."',
'".$exif['EXIF']['ExposureTime']."',
'".$exif['EXIF']['ISOSpeedRatings']."'
)";
db_exec($strSQLInsert,$conn);
}