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

191
functions.php Normal file
View File

@@ -0,0 +1,191 @@
<?php
/* Fonction month(): convertit le mois (nb) en mois (texte) francais
photo-du-mois.php
*/
function month($w) {
//setlocale(LC_TIME, 'fr_FR');
$m = date('m', strtotime($w)); // month
$y = date('Y', strtotime($w)); // year
//echo $m . "-" . $y;
// or any other locales like pl_PL, cs_CZ, fr_FR, zh, zh_Hans, ...
$locale = 'fr_FR';
$dateFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::LONG, // date type
IntlDateFormatter::NONE // time type
);
$dateFormatter->setPattern('LLLL'); // full month name with NO DECLENSION ;-)
$months_locale = [];
for ($month_number = 1; $month_number <= 12; ++$month_number) {
$months_locale[] = $dateFormatter->format(
// 'n' => month number with no leading zeros
DateTime::createFromFormat('n', (string)$month_number)
);
}
$my = ucfirst($months_locale[(int)$m]) . " " . $y;
//echo $my;
return $my;
}
/* Fonctions get_gps() et gps2Num(): extrait les coord GPS depuis les exifs
insert_bdd.php
*/
function gps2Num($coordPart){
$parts = explode('/', $coordPart);
if(count($parts) <= 0)
return 0;
if(count($parts) == 1)
return $parts[0];
return floatval($parts[0]) / floatval($parts[1]);
}
function get_gps($exif) {
if($exif && isset($exif['GPS'])){
$GPSLatitudeRef = isset($exif['GPS']['GPSLatitudeRef']) ? $exif['GPS']['GPSLatitudeRef'] : '';
$GPSLatitude = isset($exif['GPS']['GPSLatitude']) ? $exif['GPS']['GPSLatitude'] : '';
$GPSLongitudeRef = isset($exif['GPS']['GPSLongitudeRef']) ? $exif['GPS']['GPSLongitudeRef'] : '';
$GPSLongitude = isset($exif['GPS']['GPSLongitude']) ? $exif['GPS']['GPSLongitude'] : '';
$GPSAltitude = isset($exif['GPS']['GPSAltitude']) ? $exif['GPS']['GPSAltitude'] : '';
$lat_degrees = count($GPSLatitude) > 0 ? gps2Num($GPSLatitude[0]) : 0;
$lat_minutes = count($GPSLatitude) > 1 ? gps2Num($GPSLatitude[1]) : 0;
$lat_seconds = count($GPSLatitude) > 2 ? gps2Num($GPSLatitude[2]) : 0;
$lon_degrees = count($GPSLongitude) > 0 ? gps2Num($GPSLongitude[0]) : 0;
$lon_minutes = count($GPSLongitude) > 1 ? gps2Num($GPSLongitude[1]) : 0;
$lon_seconds = count($GPSLongitude) > 2 ? gps2Num($GPSLongitude[2]) : 0;
$lat_direction = ($GPSLatitudeRef == 'W' or $GPSLatitudeRef == 'S') ? -1 : 1;
$lon_direction = ($GPSLongitudeRef == 'W' or $GPSLongitudeRef == 'S') ? -1 : 1;
$latitude = $lat_direction * ($lat_degrees + ($lat_minutes / 60) + ($lat_seconds / (60*60)));
$longitude = $lon_direction * ($lon_degrees + ($lon_minutes / 60) + ($lon_seconds / (60*60)));
$alt = explode('/', $exif['GPS']["GPSAltitude"]);
$altitude = (isset($alt[1])) ? ($alt[0] / $alt[1]) : $alt[0];
}
else {
$latitude = '';
$longitude = '';
$altitude = '';
}
return array('latitude'=>$latitude, 'longitude'=>$longitude, 'altitude'=>$altitude);
}
/* Fonction create_thumb(): Création des vigntettes
insert_bdd.php
*/
function create_thumb($thumb_w, $thumb_h, $image) {
list($origin_w, $origin_h) = getimagesize($image);
$origin_ratio = round($origin_w / $origin_h, 1);
$outFile = str_replace("photos/img", "photos/thumb", $image);
if ($origin_w != null && $origin_h != null) {
if ($thumb_w / $thumb_h > $origin_ratio) {
$thumb_w = $thumb_h * $origin_ratio;
} else {
$thumb_h = $thumb_w / $origin_ratio;
}
if ($origin_w >= 400 && $origin_h >= 400) {
$image = new Imagick($image); // !!!
$image->thumbnailImage($thumb_w, $thumb_h);
$image->writeImage($outFile);
$image->destroy();
}
}
}
/* Fonction in_bdd(): test si la photo est déjà dans la bdd
insert_bdd.php
*/
function in_bdd($image) {
try {
$conn3 = new PDO('sqlite:db_photo.sqlite3');
#$query3 = "SELECT filename FROM photos WHERE instr(filename, '". $file . "') > 0;";
$query3 = "SELECT filename FROM photos WHERE filename = :filename";
$stmt = $conn3->prepare($query3);
$stmt->bindParam(':filename', $image, PDO::PARAM_STR);
$stmt->execute();
$result3 = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result3) > 0) {
return true;
} else {
return false;
}
$conn3 = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
//
function _pr($d) {
echo "<div style='border: 1px solid#ccc; padding: 10px;'>";
echo '<strong>' . debug_backtrace()[0]['file'] . ' ' . debug_backtrace()[0]['line'] . '</strong>';
echo "</div>";
echo '<pre>';
if(is_array($d)) {
print_r($d);
} else if(is_object($d)) {
var_dump($d);
}
echo '</pre>';
}
/* return geo exif in a nice form
*/
function geo_frac2dec($str) {
@list( $n, $d ) = explode( '/', $str );
if ( !empty($d) )
return $n / $d;
return $str;
}
/*
33° 52.37 0″ S 151° 9.06 0″ E
*/
function geo_pretty_fracs2dec($fracs) {
return geo_frac2dec($fracs[0]) . '&deg; ' .
geo_frac2dec($fracs[1]) . '&prime; ' .
geo_frac2dec($fracs[2]) . '&Prime; ';
}
/*
to GoogleMaps
*/
function geo_single_fracs2dec($fracs) {
return geo_frac2dec($fracs[0]) +
geo_frac2dec($fracs[1]) / 60 +
geo_frac2dec($fracs[2]) / 3600;
}
?>