Jump to content
Larry Ullman's Book Forums

tonywuk

Members
  • Posts

    3
  • Joined

  • Last visited

tonywuk's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hi HartleySan , thanks for your note. I'm going to stick with sizing on the fly for now, and see how the server copes if this site gets busy. For now I need the flexibility until the design is stable (probably never...). Thanks for that link. There's a comment at the bottom of the page from 'pushedx' which would seem to reveal the cause of the problem with $_SESSION. It suggests that the session variables are only written (= updated) at the end of the script, so my 3rd or nth entry will be the only one used, the previous values will be overwritten. So it takes the last set of values and iterates n times with those values. In this case, the $_GET array would appear to be the only way. Btw, Jonathan - yes the headers already sent is a problem I've encountered when serving a jpg file via a script. That's why the external script must not even have any white space above the php tags - even a space is 'output'. all the best //tony
  2. Hi everyone and thank you very much for your responses. A couple of answers: - We don't want to expose the URL of the pictures, so they are stored above the webroot. This means they can't be called from within the html using a simple path (by either us or a picture-stealer-person). Also we want to use a single master picture and resize it as required (on the fly) so if the site design changes we can make simple changes to the code to get a new size. The alternative would mean keeping or remaking many pictures and storing them accordingly. - I had considered the $_GET superglobal, but initial tests had not proved successful so I had been concentrating on fixing the $_SESSION problem. However, since there doesn't seem to be a way of getting the $_SESSION to work, I have now recoded using the $_GET method for the width and name parameters. And it works! About which I am both relieved and pleased! It's crazy though as other session variables are recovered and used, so it does seem to be down to the repetitive nature of the code to display multiple pictures. - I don't think there is a problem using <img src="aScript.php" /> method and I'm not aware of any other way of doing it. Given an alt attribute it certainly validates. So many thanks for the stimulus of your responses. I'd prefer not to even expose the picture's name, but given the dead-end of the $_SESSION route, at least the $_GET method is up and working. Thank you all. //tony
  3. 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
×
×
  • Create New...