<?php

// valeur par défaut
$rank = -1;
// Surcharge par les arguments
extract($_REQUEST, EXTR_IF_EXISTS);

$logo='topisto_vert_tr.png';

$block_image = @imagecreatefrompng($logo);

$width = imagesx($block_image);
$height = imagesy($block_image);

// create the destination/output image.
$img=imagecreatetruecolor( $width, $height );

// enable alpha blending on the destination image.
imagealphablending($img, false);
imagesavealpha($img,true);


// Allocate a transparent color and fill the new image with it.
// Without this the image will have a black background instead of being transparent.
//$transparent = imagecolorallocatealpha( $img, 255, 255, 255, 127 );
//imagefill( $img, 0, 0, $transparent );

// copy the thumbnail into the output image.
// imagecopyresampled($img,$block_image, 0, 0, 0, 0, $width, $height, $width, $height );

$files = glob('logo/tr/topisto_*.png');
usort($files, function($a, $b) {
  return filemtime($a) > filemtime($b);
});

if ($rank < 0)
{
  shuffle($files);
  $rank = 0;
}

// Borner l'index aux valeurs du tableau
$rank = $rank % count($files);
 
$superpose = @imagecreatefrompng($files[$rank]);

imagecopyresampled($img,$superpose, 0, 0, 0, 0, $width, $height, imagesx($superpose), imagesy($superpose));

imagedestroy($superpose);

imagecopymerge($img, $block_image, 0, 0, 0, 0, $width, $height, 45);

// ---
// --- envoyer l'image au navigateur
// ---
header("Content-Type: image/png");
imagepng($img);

imagedestroy($img);
imagedestroy($block_image);

?>
