I am trying to use the below chunk of code to control the height and
width of displayed images, based on the users screen height.
This works if the $baseimage is set to 800 as shown. The echo lines
display 1024800, as expected, on the web page and the width= and height
= lines set the displayed image size as desired.
If I try to use $baseimage = $displayheight instead (Which is what I
want) then the two echo lines dispay 10241024, as expected, on the web
page. But it then sets width=0 and height=0 for the image, so the image
is not displayed.
The echo always displays 1024 on the screen, thus I assume that it is
not a conflict between the Javascript and PHP stuff since that does seem
to indicate the page knows what the height is, it just does not want to
use the number in the calculations.
If I omit all $baseimage stuff and in the calculations section use
$displayheight instead of $baseimage I have same problems as above.
If I add additional lines to check for is_numeric, then everything
indicates that $displayheight and $baseimage are both numeric.
The $picturespecs array comes from elsewhere and is good (Example 600,
800) since it works if I preset $baseimage to 800.
A bit lengthy, sorry, just trying to include anything possibly
pertinent. Could someone tell me where I have gone wrong here.
Thanks,
Marvin
// xxxxxxxx Get the screen width and set base image size xxx
$displayheight = "<SCRIPT language=\"javascript\">\n var res =
screen.height;\n document.write(res);\n </SCRIPT>";
$baseimage = 800;
// $baseimage = $displayheight;
echo $displayheight;
echo $baseimage;
// xxxxxxxxx Calculate desired image height and width xxxxx
If ($picturespecs[0] > $picturespecs[1])
{$percentage = ($baseimage / $picturespecs[0]);}
else
{$percentage = ($baseimage / $picturespecs[1]);}
$width = round($picturespecs[0] * $percentage);
$height = round($picturespecs[1] * $percentage);
$imagesize = "width=" . $width . " height=" . $height;