Code: Select all
<?php
########## settings ##########
## note: both the template and the randomly selected mini-images must be saved as png-24
// filenames (and if needed, paths) for count- and templatefile
$template = 'net_tpl_square.png';
$count_file = 'count';
// location of randomly selected mini-images ( set it to '.' to have same directory)
$folder = 'img/';
// mini-images to randomly output (if you want to have all pngs in the folder, just use 'all'
$files = array (
'all'
#'pic1.png','pic2.png','pic3.png'
);
// font settings (use the absolute path, ie: C:\Windows\Fonts\Arial.ttf
$font = realpath ('./KROE0553.TTF');
$fsize = 6; // font size (width)
########## /settings ##########
########## read & update views ##########
// read from counter-file
$count = @file ($count_file);# or die ('could not load file');
// views-text
$views = ++$count[0];
// update views
$c_file = @fopen ($count_file, 'w');# or die ('could not open file for writing');
if ($c_file):
@fwrite ($c_file, $views);# or die ('could not update file');
@fclose ($c_file);
endif;
########## /read & update views ##########
########## /choose mini-image ##########
// should all pngs in the folder be used?
if ($files[0] == 'all') {
$files = array (); // empty files
if ($f_folder = opendir ($folder)): // open folder
while ($ofile = readdir ($f_folder)):
if ($ofile == '..' || $ofile == '.') continue;
$img_info = getimagesize ($folder.$ofile);
if ($img_info['mime'] == 'image/png')
$files[] = $folder.$ofile; // add to files
endwhile;
endif;
}
// pick a filename from list for displaying
$rnd_file = array_rand ($files);
########## /choose mini-image ##########
########## output final image ##########
// create images for template and mini
$output = imagecreatefrompng ($template);# or die ('could not load template-image'); ##<<<<< BREAKS HERE
$insert = imagecreatefrompng ($files[$rnd_file]);# or die ('could not load mini-image');
// merge the images together
imagecopy ($output,$insert,4,12,0,0,260,62);# or die ('could not insert mini-image');
// colors
$fc = imagecolorallocate ($output, 95, 97, 100); // foreground color
$bc = imagecolorallocate ($output, 250, 250, 250); // shadow color
// output views-string
imagettftext ($output, $fsize, 0, 229, 10, $bc, $font, $views);
imagettftext ($output, $fsize, 0, 228, 9, $fc, $font, $views);# or die ('could not echo views');
#### create the image ####
header ("Content-type: image/png");
#header ("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
#header ("Expires: ".gmdate("D, d M Y H:i:s", time() + 60*3)." GMT");
#header ("Pragma: no-cache");
imagepng ($output) or die ('could not create the image');
#### /create the image ####
########## /output final image ##########
?>A huge thanks in advance.