Navigation
Main
 
Code

[Back to list] [Execute]

<?php
// Velox Letum (2005)
// elementation@gmail.com
// http://www.nanoshock.net
 
$image = $HTTP_GET_VARS['image'];
$image = str_replace(array("/", ".."), "", $image);
$overlay = 'overlay.png';
$dir = '../hresources/';
 
// A default if for the demo...remove if you wish.
if ($image == NULL) {
    $image = 'donutland.jpg';
}
 
// Find if image exists
if (!file_exists($dir . $image)) {
    die("Image does not exist.");
}
 
// Set offset from bottom-right corner
$w_offset = 0;
$h_offset = 0;
 
$extension = strtolower(substr($image, strrpos($image, ".") + 1));
 
// Load image from file
switch ($extension)
{
    case 'jpg':
        $background = imagecreatefromjpeg($dir . $image);
        break;
    case 'jpeg':
        $background = imagecreatefromjpeg($dir . $image);
        break;
    case 'png':
        $background = imagecreatefrompng($dir . $image);
        break;
    case 'gif':
        $background = imagecreatefromgif($dir . $image);
        break;
    default:
        die("Image is of unsupported type.");
}
 
// Find base image size
$swidth = imagesx($background);
$sheight = imagesy($background);
 
// Turn on alpha blending
imagealphablending($background, true);
 
// Create overlay image
$overlay = imagecreatefrompng($dir . $overlay);
 
// Get the size of overlay
$owidth = imagesx($overlay);
$oheight = imagesy($overlay);
 
// Overlay watermark
imagecopy($background, $overlay, $swidth - $owidth - $w_offset, $sheight - $oheight - $h_offset, 0, 0, $owidth, $oheight);
 
// Output header and final image
header("Content-type: image/jpeg");
header("Content-Disposition: filename=" . $image);
imagejpeg($background);
 
// Destroy the images
imagedestroy($background);
imagedestroy($overlay);
 
?>
© 2005 Nanoshock.net. All rights reserved.