<?php
header ("Content-type: image/jpeg"); // L'image que l'on va créer est un jpeg

$url=$_GET['url'];
$aurl = explode('/',$url);//pour trouver le nom du fichier
$anb = count($aurl) -1;
$nom=$aurl[$anb];

// pour avoir l'adresse sans nom d'image
$adresse = substr($url, 0, -(strlen($nom)+1));
$test_thumb='gallerie/img/'.$_GET['dossier'].'/thumbs/'.$nom;
$test_dir_thumb='gallerie/img/'.$_GET['dossier'].'/thumbs';

//si le dossier thumbs n'existe pas on le crée
if(!file_exists($test_dir_thumb)){
mkdir('gallerie/img/'.$_GET['dossier'].'/thumbs/',0777);
}

if(!file_exists($test_thumb)){
$source = imagecreatefromjpeg($url); // La photo est la source
$destination = imagecreatetruecolor(50, 50); // On crée la miniature vide

// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);

// On crée la miniature
imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source);

// On enregistre la miniature sous le nom "mini_couchersoleil.jpg"
imagejpeg($destination, 'gallerie/img/'.$_GET['dossier'].'/thumbs/'.$nom);
}
?>
