PHP Code:
<?php
$path="data/";
$files=array();
$dirp = @opendir($path);
if ($dirp){
$count = 0;
while ($file_name = readdir($dirp))
{
if (($file_name != ".") && ($file_name != "..") && (!is_dir($path.$file_name)) && strpos($file_name,"_log")===false){
$files[] = $path.$file_name;
$count++;
}
}
closedir($dirp);
}
$pic2 = $files[rand(0,count($files)-1)]; // take a random image from the list
header("Content-type: image/jpeg");
/////////////////////////////////////////////////////////////////////////////////////////////////////
$picsize=getimagesize($pic2);
$source_x = $picsize[0];
$source_y = $picsize[1];
$kvaliteet = 85; // quality, dont use over 85, pointless
$maxw = 500; // maximum width for the sig, the image will be resized to this width
$crop = 150; // maximum height for the sig, image will be cropped from teh centre
$siz = $picsize;
if (($siz[0] > $maxw))
{
$neww = $maxw;
$x = $siz[0]/$maxw;
$newh = $siz[1]/$x;
}
else
{
$neww = $siz[0];
$newh = $siz[1];
}
$ext = strtolower(strrchr($pic2,"."));
switch($ext){
case ".gif": $source_id = ImageCreateFromGIF( $pic2 ); break;
case ".jpg": $source_id = ImageCreateFromJPEG( $pic2 ); break;
case ".png": $source_id = ImageCreateFromPNG( $pic2 ); break;
default: $source_id = ImageCreateFromJPEG( $pic2 ); break;
}
$target_id=imagecreatetruecolor($neww, $newh);
$target_id2=imagecreatetruecolor($neww, $crop);
$miniS = newSize($picsize,100,120);
$mini = imagecreatetruecolor($miniS[0], $miniS[1]);
$crophS = $newh/2-$crop/2;
imagecopyresampled( $target_id, $source_id, 0, 0, 0, 0, $neww, $newh, $source_x, $source_y );
imagecopyresampled( $target_id2, $target_id, 0, 0, 0, $crophS, $neww, $crop, $neww, $crop );
imagecopyresampled( $mini, $source_id, 0, 0, 0, 0, $miniS[0], $miniS[1], $source_x, $source_y);
$target_id2 = image_overlap($target_id2,$mini);
$waterM = ImageCreateFromGIF("waterm.gif"); // watermark image file which will be overlapped
imagecolorset($waterM,0,0xA0,0xFF,0xE0); // set the first colo from the palette to this new color
imagecolorset($waterM,2,0x00,0xD0,0xA0); // and second
$target_id2 = image_overlap($target_id2,$waterM,1,55);
imagejpeg ($target_id2,"",$kvaliteet);
imagedestroy($target_id);
imagedestroy($target_id2);
imagedestroy($source_id);
imagedestroy($mini);
imagedestroy($waterM);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function image_overlap($background, $foreground,$zero=0,$trans=60)
{
$insertWidth = imagesx($foreground);
$insertHeight = imagesy($foreground);
$imageWidth = imagesx($background);
$imageHeight = imagesy($background);
if(!$zero){
$overlapX = $imageWidth-$insertWidth-5;
$overlapY = $imageHeight-$insertHeight-30;
}else{
$overlapX=0;
$overlapY=$imageHeight-$insertHeight;
}
// imagecolortransparent($foreground,imagecolorat($foreground,0,0));
imagecopymerge($background,$foreground,$overlapX,$overlapY,0,0,$insertWidth,$insertHeight,$trans);
return $background;
}
function newSize($siz,$maxw,$maxh)
{
if (($siz[0] > $maxw) || ($siz[1] > $maxh))
{
if (($siz[0]/$maxw) > ($siz[1]/$maxh))
{
$neww = $maxw;
$x = $siz[0]/$maxw;
$newh = $siz[1]/$x;
}
if (($siz[0]/$maxw) < ($siz[1]/$maxh))
{
$newh = $maxh;
$x = $siz[1]/$maxh;
$neww = $siz[0]/$x;
}
if (($siz[0]/$maxw) == ($siz[1]/$maxh))
{
$neww = $maxw;
$newh = $maxh;
}
}
else
{
$neww = $siz[0];
$newh = $siz[1];
}
return array($neww,$newh);
}
?>
sorry for the bad look of the code but it was just some file that got edited 1000 times for different purposes.