Add phtoswipe

This commit is contained in:
2022-03-16 12:26:37 +01:00
parent f67ed00dd4
commit 43a2bfba83
11 changed files with 7564 additions and 810 deletions

205
insert_bdd.php Normal file
View File

@@ -0,0 +1,205 @@
<?php
include 'functions.php';
$base = 'db_photo.sqlite3';
// Taille des vignettes
$th_w = 300;
$th_h = 300;
//Get a list of file paths using the glob function.
$fileList = glob('photos/img/*');
// Création de la base et de la table photos
$conn = new PDO("sqlite:db_photo.sqlite3");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "CREATE TABLE IF NOT EXISTS photos (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
filename TEXT NOT NULL,
date TEXT,
lens TEXT,
exposure INTEGER,
iso INTEGER,
width INTEGER,
height INTEGER,
html TEXT,
aperture TEXT,
model TEXT,
lat REAL,
long REAL,
alt REAL,
legende TEXT,
copyright TEXT,
titre TEXT,
createur TEXTr,
keywords TEXT,
UNIQUE(filename)
)";
$conn->exec($query);
$conn = null;
$i = 1;
// Ajout de données dans la table
foreach($fileList as $file){
$x = in_bdd($file);
if ($x == false) { //false
if ($exif = @exif_read_data($file, 0, true )) {
//_pr($exif);
# YYYY-MM-DD HH:MM:SS.SSS - 2019:10:01 14:03:12
$da = isset($exif['EXIF']['DateTimeOriginal']) ? $exif['EXIF']['DateTimeOriginal'] : '';
$obj = isset($exif['EXIF']['UndefinedTag:0xA434']) ? $exif['EXIF']['UndefinedTag:0xA434'] : '';
$ex = isset($exif['EXIF']['ExposureTime']) ? $exif['EXIF']['ExposureTime'] : '';
$iso = isset($exif['EXIF']['ISOSpeedRatings']) ? $exif['EXIF']['ISOSpeedRatings'] : '';
$wi = isset($exif['COMPUTED']['Width']) ? $exif['COMPUTED']['Width'] : '';
$he = isset($exif['COMPUTED']['Height']) ? $exif['COMPUTED']['Height'] : '';
$ht = isset($exif['COMPUTED']['html']) ? $exif['COMPUTED']['html'] : '';
$ap = isset($exif['COMPUTED']['ApertureFNumber']) ? $exif['COMPUTED']['ApertureFNumber'] : '';
$mod = isset($exif['IFD0']['Model']) ? $exif['IFD0']['Model'] : '';
$gps = get_gps($exif);
$photos[$i] = array(
'filename' => $file,
'date' => $da,
'lens' => $obj,
'exposure' => $ex,
'iso' => $iso,
'width' => $wi,
'height' => $he,
'html' => $ht,
'aperture' => $ap,
'model' => $mod,
'lat' => $gps['latitude'],
'long' => $gps['longitude'],
'alt' => $gps['altitude']
);
//_pr($photos);
}
if ($iptc = getimagesize($file, $info)) {
if (isset($info["APP13"])) {
$mots = "";
$iptc = iptcparse ($info["APP13"]);
$legende = (isset($iptc["2#120"][0])) ? $iptc["2#120"][0] : '';
$copyright = (isset($iptc["2#116"][0])) ? $iptc["2#116"][0] : '';
$titre = (isset($iptc["2#105"][0])) ? $iptc["2#105"][0] : '';
$createur = (isset($iptc["2#080"][0])) ? $iptc["2#080"][0] : '';
$mots_cles = (isset($iptc["2#025"])) ? $iptc["2#025"] : '';
foreach ($mots_cles as $m) {
$mots .= $m . ",";
}
$mots = substr($mots, 0, -1);
$photos[$i]['legende'] = $legende;
$photos[$i]['copyright'] = $copyright;
$photos[$i]['titre'] = $titre;
$photos[$i]['createur'] = $createur;
$photos[$i]['mots_cles'] = $mots;
//_pr($photos);
}
}
}
$i++;
}
//_pr($photos);
// Insertion des photos dans la base
// Création des vignettes
try {
$conn2 = new PDO('sqlite:db_photo.sqlite3');
$query2 = "INSERT OR IGNORE INTO photos (filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords) VALUES (:filename, :date, :lens, :exposure, :iso, :width, :height, :html, :aperture, :model, :lat, :long, :alt, :legende, :copyright, :titre, :createur, :keywords)";
$stmt = $conn2->prepare($query2);
$stmt->bindParam(':filename', $file);
$stmt->bindParam(':date', $da);
$stmt->bindParam(':lens', $obj);
$stmt->bindParam(':exposure', $ex);
$stmt->bindParam(':iso', $iso);
$stmt->bindParam(':width', $wi);
$stmt->bindParam(':height', $he);
$stmt->bindParam(':html', $ht);
$stmt->bindParam(':aperture', $ap);
$stmt->bindParam(':model', $mod);
$stmt->bindParam(':lat', $gps['latitude']);
$stmt->bindParam(':long', $gps['longitude']);
$stmt->bindParam(':alt', $gps['altitude']);
$stmt->bindParam(':legende', $leg);
$stmt->bindParam(':copyright', $cop);
$stmt->bindParam(':titre', $tit);
$stmt->bindParam(':createur', $crea);
$stmt->bindParam(':keywords', $mot);
if (isset($photos)) {
foreach ($photos as $item) {
$file = $item['filename'];
$da = $item['date'];
$obj = $item['lens'];
$ex = $item['exposure'];
$iso = $item['iso'];
$wi = $item['width'];
$he = $item['height'];
$ht = $item['html'];
$ap = $item['aperture'];
$mod = $item['model'];
$gps['latitude'] = $item['lat'];
$gps['longitude'] = $item['long'];
$gps['altitude'] = $item['alt'];
$leg = $item['legende'];
$cop = $item['copyright'];
$tit = $item['titre'];
$crea = $item['createur'];
$mot = $item['mots_cles'];
create_thumb($th_w, $th_h, $file);
$stmt->execute();
}
}
$conn2 = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
/* Affichage depuis la bdd */
/**/
try {
$conn4 = new PDO('sqlite:db_photo.sqlite3');
$query4 = "SELECT filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords FROM photos WHERE id >= ? AND id <= ? ORDER BY date DESC";
$stmt = $conn4->prepare($query4);
# id 1 -> 3
$stmt->execute(array(1, 3));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
_pr($result);
$conn4 = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
?>