Exemplo n.º 1
0
<?php

namespace Aen\ExifGallery\Image;

use Aen\ExifGallery\Image\ImageUploader;
use Aen\Library\ExifTool\ExifTool;
use Aen\Library\ExifTool\FileModel;
require_once "ImageUploader.php";
require_once "../../Library/ExifTool/ExifTool.php";
require_once "../../Library/ExifTool/FileModel.php";
$uploader = new ImageUploader("../../../../uploads/");
$uploaded_file = $uploader->upload();
if (isset($uploaded_file)) {
    $exiftool = new ExifTool("");
    $model = new FileModel(pathinfo(basename($uploaded_file))['filename'] . ".json", "../../../../data/");
    $metas = $exiftool->getMetadata($uploaded_file);
    $model->saveToFile($metas);
    $exiftool->getXMPdata($uploaded_file, "../../../../data/xmp/" . pathinfo(basename($uploaded_file))['filename'] . ".xmp");
    $img = array('name' => isset($metas[0]["XMP"]["Title"]) ? $metas[0]["XMP"]["Title"] : '', 'creator' => isset($metas[0]['XMP']["Creator"]) ? $metas[0]['XMP']["Creator"] : '', 'filename' => pathinfo(basename($uploaded_file))['filename'], 'url' => "uploads/" . $metas[0]["File"]["FileName"]);
    appendToFile("../../../../images.json", json_encode($img));
}
function appendToFile($file, $data = array())
{
    if (file_exists($file)) {
        $inp = file_get_contents($file);
        $tempArray = json_decode($inp, true);
        if (isset($tempArray) && !empty($tempArray)) {
            array_push($tempArray, $data);
        } else {
            $tempArray = [$data];
        }
Exemplo n.º 2
0
 public function save()
 {
     //var_dump($_POST);
     $name = $this->request->getGetParam('name');
     $metadatas = ImageJson::readImage($name)[0];
     $data = array(array("SourceFile" => "./uploads/" . basename($metadatas["SourceFile"]), "XMP:Creator" => isset($_POST["prop-creator"]) && !empty($_POST["prop-creator"]) ? $_POST["prop-creator"] : (isset($metadatas["XMP"]["Creator"]) ? $metadatas["XMP"]["Creator"] : ""), "XMP:Title" => isset($_POST["prop-title"]) && !empty($_POST["prop-title"]) ? $_POST["prop-title"] : (isset($metadatas["XMP"]["Title"]) ? $metadatas["XMP"]["Title"] : ""), "XMP:Description" => isset($_POST["prop-desc"]) && !empty($_POST["prop-desc"]) ? $_POST["prop-desc"] : (isset($metadatas["XMP"]["Description"]) ? $metadatas["XMP"]["Description"] : ""), "XMP:Rights" => isset($_POST["prop-rights"]) && !empty($_POST["prop-rights"]) ? $_POST["prop-rights"] : (isset($metadatas["XMP"]["Rights"]) ? $metadatas["XMP"]["Rights"] : ""), "XMP:CreateDate" => isset($_POST["prop-y"]) && isset($_POST["prop-m"]) && isset($_POST["prop-d"]) && !empty($_POST["prop-y"]) ? $_POST["prop-y"] . ":" . $_POST["prop-m"] . ":" . $_POST["prop-d"] : (isset($metadatas["XMP"]["CreateDate"]) ? $metadatas["XMP"]["CreateDate"] : ""), "XMP:Subject" => isset($_POST["prop-Keywords"]) && !empty($_POST["prop-Keywords"]) ? explode(", ", $_POST["prop-Keywords"]) : (isset($metadatas["XMP"]["Subject"]) ? $metadatas["XMP"]["Subject"] : array()), "XMP:State" => isset($_POST["prop-state"]) && !empty($_POST["prop-state"]) ? $_POST["prop-state"] : (isset($metadatas["XMP"]["State"]) ? $metadatas["XMP"]["State"] : ""), "XMP:City" => isset($_POST["prop-City"]) && !empty($_POST["prop-City"]) ? $_POST["prop-City"] : (isset($metadatas["XMP"]["City"]) ? $metadatas["XMP"]["City"] : ""), "XMP:Country" => isset($_POST["prop-Country"]) && !empty($_POST["prop-Country"]) ? $_POST["prop-Country"] : (isset($metadatas["XMP"]["Country"]) ? $metadatas["XMP"]["Country"] : ""), "IPTC:By-line" => isset($_POST["prop-creator"]) && !empty($_POST["prop-creator"]) ? $_POST["prop-creator"] : (isset($metadatas["IPTC"]["By-line"]) ? $metadatas["IPTC"]["By-line"] : ""), "IPTC:Headline" => isset($_POST["prop-title"]) && !empty($_POST["prop-title"]) ? $_POST["prop-title"] : (isset($metadatas["IPTC"]["Headline"]) ? $metadatas["IPTC"]["Headline"] : ""), "IPTC:Caption-Abstract" => isset($_POST["prop-desc"]) && !empty($_POST["prop-desc"]) ? $_POST["prop-desc"] : (isset($metadatas["IPTC"]["Caption-Abstract"]) ? $metadatas["IPTC"]["Caption-Abstract"] : ""), "IPTC:CopyrightNotice" => isset($_POST["prop-rights"]) && !empty($_POST["prop-rights"]) ? $_POST["prop-rights"] : (isset($metadatas["IPTC"]["CopyrightNotice"]) ? $metadatas["IPTC"]["CopyrightNotice"] : ""), "IPTC:DateCreated" => isset($_POST["prop-y"]) && isset($_POST["prop-m"]) && isset($_POST["prop-d"]) && !empty($_POST["prop-y"]) ? $_POST["prop-y"] . ":" . $_POST["prop-m"] . ":" . $_POST["prop-d"] : (isset($metadatas["IPTC"]["DateCreated"]) ? $metadatas["IPTC"]["DateCreated"] : ""), "IPTC:Keywords" => isset($_POST["prop-Keywords"]) && !empty($_POST["prop-Keywords"]) ? explode(", ", $_POST["prop-Keywords"]) : (isset($metadatas["IPTC"]["Keywords"]) ? $metadatas["IPTC"]["Keywords"] : array()), "IPTC:Province-State" => isset($_POST["prop-state"]) && !empty($_POST["prop-state"]) ? $_POST["prop-state"] : (isset($metadatas["IPTC"]["Province-State"]) ? $metadatas["IPTC"]["Province-State"] : ""), "IPTC:City" => isset($_POST["prop-City"]) && !empty($_POST["prop-City"]) ? $_POST["prop-City"] : (isset($metadatas["IPTC"]["City"]) ? $metadatas["IPTC"]["City"] : ""), "IPTC:Country-PrimaryLocationName" => isset($_POST["prop-Country"]) && !empty($_POST["prop-Country"]) ? $_POST["prop-Country"] : (isset($metadatas["IPTC"]["Country-PrimaryLocationName"]) ? $metadatas["IPTC"]["Country-PrimaryLocationName"] : ""), "EXIF:Artist" => $_POST["prop-creator"], isset($_POST["prop-creator"]) && !empty($_POST["prop-creator"]) ? $_POST["prop-creator"] : (isset($metadatas["EXIF"]["Artist"]) ? $metadatas["EXIF"]["Artist"] : ""), "EXIF:ImageDescription " => isset($_POST["prop-desc"]) && !empty($_POST["prop-desc"]) ? $_POST["prop-desc"] : (isset($metadatas["EXIF"]["ImageDescription"]) ? $metadatas["EXIF"]["ImageDescription"] : ""), "EXIF:Copyright " => isset($_POST["prop-rights"]) && !empty($_POST["prop-rights"]) ? $_POST["prop-rights"] : (isset($metadatas["EXIF"]["Copyright"]) ? $metadatas["EXIF"]["Copyright"] : ''), "EXIF:CreateDate " => isset($_POST["prop-y"]) && isset($_POST["prop-m"]) && isset($_POST["prop-d"]) && !empty($_POST["prop-y"]) ? $_POST["prop-y"] . ":" . $_POST["prop-m"] . ":" . $_POST["prop-d"] : (isset($metadatas["EXIF"]["CreateDate"]) ? $metadatas["EXIF"]["CreateDate"] : "")));
     file_put_contents('./data/tmp.json', json_encode($data));
     $exiftool = new ExifTool("./uploads/");
     $exiftool->setMetadata(basename($metadatas["SourceFile"]), "./data/tmp.json");
     $metas = $exiftool->getMetadata(basename($metadatas["SourceFile"]));
     $model = new FileModel($name . ".json", "./data/");
     $model->saveToFile($metas);
     $exiftool->getXMPdata(basename($metas[0]["SourceFile"]), "data/xmp/" . $name . ".xmp");
     //change image list file
     $images = ImageJson::readList();
     foreach ($images as $key => $image) {
         $image = json_decode($image, true);
         if ($image["filename"] == $name) {
             $images[$key] = json_encode(array("name" => isset($_POST["prop-title"]) && !empty($_POST["prop-title"]) ? $_POST["prop-title"] : $metadatas["XMP"]["Title"], 'creator' => isset($_POST["prop-creator"]) && !empty($_POST["prop-creator"]) ? $_POST["prop-creator"] : $metadatas["XMP"]["Creator"], "filename" => $image["filename"], "url" => $image["url"]));
             break;
         }
     }
     file_put_contents("images.json", json_encode($images));
     header("Location: index.php?t=image&a=view&name=" . $name);
     die;
 }