<?php
    
// Make sure that we are logged in:
    
function is_logged()
    {
    if (!isset(
$_SESSION['islogged']) || $_SESSION['islogged'] == false) {
    
// Return to login.php
    
header('Location: login.php');
    exit;
    }
    }

    
// To resize images, we make for them icons:
    
function create_icon($source_file$destination_file$width$quality 75)
    {
    
$icon '';    
    if (
file_exists($source_file)  && isset($destination_file))
    {
    
$size  getimagesize($source_file);
    
$w number_format($width0',''');
    
$h number_format(($size[1] / $size[0]) * $width0',''');        
    
$icon =  copy_image($source_file$destination_file$w$h$quality);
    }
    return 
basename($icon);
    }

    
// copy images from source to destination:
    
function copy_image($source_file$destination_file$w$h$quality 75)
    {
    
$source_tmp     pathinfo(strtolower($source_file));
    
$destination_tmp    pathinfo(strtolower($destination_file));
    
$size       getimagesize($source_file);

    if (
$destination_tmp['extension'] == "gif" || $destination_tmp['extension'] == "jpg")
    {
    
$destination_file  substr_replace($destination_file'jpg', -3);
    
$destination      imagecreatetruecolor($w$h);
    } elseif (
$destination_tmp['extension'] == "png") {
    
$dest imagecreatetruecolor($w$h);
    } else {
    return 
false;
    }

    
//  we need a file for gif, jpg, or png files:
    
switch($size[2])
    {
    case 
1:
    
$source imagecreatefromgif($source_file);
    break;
    case 
2:
    
$source imagecreatefromjpeg($source_file);
    break;
    case 
3
    
$source imagecreatefrompng($source_file);
    break;
    default:
    return 
false;
    break;
    }
    
imagecopyresampled($destination$source0000$w$h$size[0], $size[1]);
    switch(
$size[2])
    {
    case 
1:
    case 
2:
    
imagejpeg($destination,$destination_file$quality);
    break;
    case 
3:
    
imagepng($destination,$destination_file);
    }
    return 
$destination_file;
    }
    
?>