Hi Larry and others
I have a simple foreach loop accessing an array of up to 8 stored jpgs and I have also tested this with 3 simple repetitive entries. The objective of this script is to use one subroutine to generate new pictures at a chosen new width on the fly.
For each value (the master picture name) in the array I set 2 session variables and pass them to '_a_makePicByWidth.php', which is inside image tags.
// repeated test code start
$_SESSION['picName'] = $picListArray['7']['1'] . '.jpg' ;
$_SESSION['newWidth'] = 120 ;
echo '<img src="_a_makePicByWidth.php" />' ;
//repeated code end
// for testing repeated 3 times to display 3 pictures at different sizes, varying the '7' and the '120'.
I have tested with echos and all the parameters are available in the '_a_makePicByWidth.php' script, but the output is 3 times the same last picture at the last size specified, and the same happens with the foreach loop. There's 8 picture names in the test array, and the last one is shown 8 times. To further clarify, I can change the $newWidth parameter in the 3rd entry, then the output displays the last picture 3 times at the new size, so the iteration is occuring
Here's an extract from the '_a_makePicByWidth.php' script:
// there are other session parameters, these are just the relevant variables
$newWidth = $_SESSION['newWidth'] ;
$picName = $_SESSION['picName'] ;
// If I put echoes in here, I get only the last values of $picName and $newWidth whether it is the 3 test entries
// or the array/foreach loop with 8 values of filename.
// more or less straight out of the book
$srcPic = imagecreatefromjpeg($filePath . $picName);
list($width, $height) = getimagesize($filePath . $picName) ;
$newHeight = round($height * $newWidth/$width) ;
$newPic = ImageCreateTrueColor($newWidth, $newHeight) ;
imagecopyresampled($newPic, $srcPic, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
//serve the new picture
header('Content-Type: image/jpg') ;
imagejpeg($newPic);
// none of this below has any effect!
imagedestroy($newPic);
imagedestroy($srcPic);
$_SESSION['newWidth'] = '' ;
$_SESSION['picName'] = '';
$newWidth = '' ;
$picName = '' ;
$newPic = '' ;
exit();
// end of script
It's been hours and few more that I've spent on this, cannot see why the same last picture name and size are repeated. Any suggestions gratefully received.
ttfn
tony