Torna agli scripts <<< BACK
<?php
/*###########################################################################################################################################
# Fotoalbum Class
# Copyright (c)2009 Andrea Mirabella
# postmaster[at]andreamirabella.it
# http://www.andreamirabella.it/scripts.php?p=1
# License: LGPL
# Descrizione : Classe per la gestione di un fotoalbums per semplificare la creazione di fotoalbum all'utente finale.
Permette di sfogliare il contenuto di una cartella e di creare l'anteprima ridimensionata (thumbnail) delle immagini e
aggiungere il copyright (watermark).
# Description : Class to manage fotoalbums, to semplify the creation to the end user. It's possible browse folders's contents and create thumbnails
of images and add watermark on the pictures.
############################################################################################################################################*/
class Fotoalbum {
public function BrowseFolder($path = FALSE) {
//Supported Images Extensions
$extensions = array ("jpg","JPG");
// Controllo correttezza percorso
// Check if path is valid
if ($folder = opendir('./'.$path)) {
// Scorre tutto il contenuto della cartella inserice file e cartelle in due array diversi
// Check all contents of folder and put into different arrays folders and files
while ($file = readdir($folder)) {
$path_info = pathinfo($file);
if (is_dir("./".$path."/".$file)) {
if ($file != "." & $file != "..") { $directory[] = $file; }
}
if (is_file("./".$path."/".$file)){
if (in_array($path_info['extension'],$extensions)) {
if ($file != "." & $file != "..") { $files[] = $file; }
}
}
}
// Chiudo la directory - Directory Closing
closedir($folder);
// Restituiamo tutto il contenuto sotto forma di array di array
// Return al content in an array of array
$content = array ($files,$directory);
return $content;
}
else { echo "Main Directory Missing. Check Fotoalbum Settings"; exit; }
}
public function CreateThumbnails($path = FALSE) {
// Defautl Thumbnail Sizes
// Dimensioni standard Anteprima
$default_width = 150;
$default_height= 120;
// Se la cartella thumbs non esiste viene creata.
// If thumbs folder doesn't exist it will be create.
if (!is_dir($path."/thumbs/")) { mkdir($path."/thumbs/", 0755);}
$content = $this->BrowseFolder($path);
for($i=0;$i<count($content[0]);$i++) {
// Ottengo le informazioni sull'immagine originale
// Retriving imformation from original images
list($width, $height, $type, $attr) = getimagesize( $path.'/'.$content[0][$i]);
// Calcola le dimensioni delle immagini mantenendo le proporzioni
// Dimensions calculated mantaining proportions
if ($width<=$height){
$width_thumb=$width/$height*$default_height; $height_thumb = $default_height;
} else {
$width_thumb = $default_width ; $height_thumb=$height/$width*$default_width;
}
// Creo la versione ridotta dell'immagine (thumbnail)
// Thumbnail Creation
$thumbnail = imagecreatetruecolor($width_thumb, $height_thumb);
$source = imagecreatefromjpeg($path.'/'.$content[0][$i]);
imagecopyresized($thumbnail, $source, 0, 0, 0, 0, $width_thumb, $height_thumb,$width,$height);
// Salvo l'immagine ridimensionata
// Saving resized image
imagejpeg($thumbnail,$path."/thumbs/".$content[0][$i],75);
imagedestroy($thumbnail);
imagedestroy($source);
}
}
public function ApplyCopyright($path = FALSE) {
$content = $this->BrowseFolder($path);
for($i=0;$i<count($content[0]);$i++) {
// Ottengo le informazioni sull'immagine originale
// Retriving imformation from original images
list($width, $height, $type, $attr) = getimagesize( $path.'/'.$content[0][$i]);
$dest = imagecreatefromjpeg($path.'/'.$content[0][$i]);
// ************* OPTIONAL *****************************************************************
// A seconda se un immagine è verticale oppure orizzontale posso decidere di utilizzare 2 copyright diversi
if ($width<=$height){ $copyright = imagecreatefrompng('../images/copyright/copyright_ori.png'); }
else { $copyright = imagecreatefrompng('../images/copyright/copyright_ori.png'); }
// Copy and merge
if ($width<=$height){
// Alta - Tall
// Posizionamento Copyright - Copyright Positioning
imagecopymerge($dest, $copyright, (imageSX($dest)/2), (imageSY($dest)-10), 0, 0, imageSX($copyright), imageSY($copyright), 75);
}
else {
// Bassa - Short
// Posizionamento Copyright - Copyright Positioning
imagecopymerge($dest, $copyright, (imageSX($dest)-10), (imageSY($dest)/2), 0, 0, imageSX($copyright), imageSY($copyright), 75);
}
// ******************************** OPTIONAL ***************************************
// Alternativa - Alternative
/*
$copyright = imagecreatefrompng('../images/copyright/copyright_ori.png');
imagecopymerge($dest, $copyright, (imageSX($dest)-10), (imageSY($dest)/2), 0, 0, imageSX($copyright), imageSY($copyright), 75);
*/
imagejpeg($dest,$path."/".$content[0][$i],75);
imagedestroy($dest);
imagedestroy($copyright);
}
}
}
?>