Accueil > > > GALLERIE PHOTO, THUMBNAIL AUTOMATIQUE
GALLERIE PHOTO, THUMBNAIL AUTOMATIQUE
Information sur la source
Description
voici une gallerie photo basique, mais tellement utile et fiable, que je vous la propose.
je l'ai developpé pour mes besoins personnel http://pictures.allboard.net
vous avez juste a placer vos images ou repertoires d'images dans /images/ et l'arborescence, les thumbnails sont generé automatiquement a l'ecran.
si les thumbnail existes deja, il sont juste affiché, sinon, il sont créé par php et placé dans le rep mirroir /thumbs/.
tres tres basique, C facilement updatable selon les besoins.
Source
- // voici le code du fichier des fonctions
-
- <?php
-
- function createthumb($name,$filename, $thumb_x, $thumb_y, $caption)
- {
- if (!file_exists($filename)){
- $img_in = imagecreatefromjpeg($name);
- $img_out = imagecreatetruecolor($thumb_x, $thumb_y);
- $tc = str_replace(".//","",$img);
- imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
- $white = imagecolorallocate($img_out, 255, 255, 255);
- $black = imagecolorallocate($img_out, 0, 0, 0);
- //imagestring($img_out,1,3,3,$caption,$black);
- //imagestring($img_out,1,2,2,$caption,$white);
- imagejpeg($img_out, $filename, 100);
- imagedestroy($img_out);
- imagedestroy($img_in);
- }
- }
-
- function createDir($from, $to) {
- $dossier=opendir($from);
- while ($fichier = readdir($dossier)) {
- $l = array('.', '..');
- if (!in_array( $fichier, $l)){
- if (is_dir($from."/".$fichier)){
- if (!file_exists($to."/".$fichier)){
- mkdir($to."/".$fichier, 0777);
- chmod($to."/".$fichier."/", 0777);
- }
- createDir($from."/".$fichier,$to."/".$fichier);
- }
- }
- }
- }
-
- function generate($fullsized , $thumbs){
- $thumb_x = "128"; // Horizontal size of thumbnail created in pixels
- $thumb_y = "96"; // Vertical size of thumbnail created in pixels
- $dossier=opendir($fullsized);
- while ($fichier = readdir($dossier)) {
- $l = array('.', '..','Thumbs.db');
- if (!in_array( $fichier, $l)){
- $tmp = $thumbs."/".$fichier;
- $tmp2 = $fullsized."/".$fichier;
- $tmpd = ereg_replace("images/","",$tmp2);
-
- if (is_dir($fullsized."/".$fichier)){
- print("
- <a href=\"?d=$tmpd&id=$id\" class=\"liens\">$fichier</a><br>
- ");
- } else {
- $img_nfo = getimagesize($fullsized."/".$fichier);
- createthumb($fullsized."/".$fichier,$thumbs."/".$fichier, $thumb_x, $thumb_y, $caption);
- $url = "javascript:showimage('big.php?show=$fullsized/$fichier','$img_nfo[0]','$img_nfo[1]')";
- print("
- <a href=\"$url\"><img border=0 src=\"$tmp\"></a>
- ");
- }
- }
- }
- }
- ?>
// voici le code du fichier des fonctions
<?php
function createthumb($name,$filename, $thumb_x, $thumb_y, $caption)
{
if (!file_exists($filename)){
$img_in = imagecreatefromjpeg($name);
$img_out = imagecreatetruecolor($thumb_x, $thumb_y);
$tc = str_replace(".//","",$img);
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
$white = imagecolorallocate($img_out, 255, 255, 255);
$black = imagecolorallocate($img_out, 0, 0, 0);
//imagestring($img_out,1,3,3,$caption,$black);
//imagestring($img_out,1,2,2,$caption,$white);
imagejpeg($img_out, $filename, 100);
imagedestroy($img_out);
imagedestroy($img_in);
}
}
function createDir($from, $to) {
$dossier=opendir($from);
while ($fichier = readdir($dossier)) {
$l = array('.', '..');
if (!in_array( $fichier, $l)){
if (is_dir($from."/".$fichier)){
if (!file_exists($to."/".$fichier)){
mkdir($to."/".$fichier, 0777);
chmod($to."/".$fichier."/", 0777);
}
createDir($from."/".$fichier,$to."/".$fichier);
}
}
}
}
function generate($fullsized , $thumbs){
$thumb_x = "128"; // Horizontal size of thumbnail created in pixels
$thumb_y = "96"; // Vertical size of thumbnail created in pixels
$dossier=opendir($fullsized);
while ($fichier = readdir($dossier)) {
$l = array('.', '..','Thumbs.db');
if (!in_array( $fichier, $l)){
$tmp = $thumbs."/".$fichier;
$tmp2 = $fullsized."/".$fichier;
$tmpd = ereg_replace("images/","",$tmp2);
if (is_dir($fullsized."/".$fichier)){
print("
<a href=\"?d=$tmpd&id=$id\" class=\"liens\">$fichier</a><br>
");
} else {
$img_nfo = getimagesize($fullsized."/".$fichier);
createthumb($fullsized."/".$fichier,$thumbs."/".$fichier, $thumb_x, $thumb_y, $caption);
$url = "javascript:showimage('big.php?show=$fullsized/$fichier','$img_nfo[0]','$img_nfo[1]')";
print("
<a href=\"$url\"><img border=0 src=\"$tmp\"></a>
");
}
}
}
}
?>
Conclusion
sur votre repertoire ftp, vous devez placer les 2 repertoires vide /images/ et /thumbs/, tous les 2 chmodés en 777.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|