I have no idea if it will work, but you could try making it a function and require() it.
<?php
require("thumbnail.php");
echo "<html><head></head><body><h2>My Picture Test</H2>";
echo thumb("green.jpg");
echo thumb("red.jpg");
echo "</body></html>";
?>
--thumbnail.php--
<?php
function thumb($sourcefile) {
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
$x_ratio = ($source_x/100);
if($x_ratio > 1)
{
$x = round($source_x/$x_ratio);
$y = round($source_y/$x_ratio);
}
else
{
$x = $picsize[0];
$y = $picsize[1];
}
$source_id = imageCreateFromJPEG("$sourcefile");
$target_id=imagecreatetruecolor($x, $y);
/ Resize the original picture and copy it into the just created image object./
$target=imagecopyresampled($target_id,$source_id, 0, 0 , 0 , 0, $x, $y, $source_x, $source_y);
Header("Content-type: image/jpeg");
$im = imagejpeg ($target_id, "", "50");
return $im;
}
?>
I'm not a 100% sure this will work, but try it out, and if it doesn't work I apologize sincerely. There might also be small errors in the code but I'm sure you can chase them out 🙂
Good Luck