Probably a Silly Code Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marvin

    Probably a Silly Code Error

    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[color=blue]
    >[/color]
    // xxxxxxxx Get the screen width and set base image size xxx
    $displayheight = "<SCRIPT language=\"java script\">\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($pictures pecs[0] * $percentage);
    $height = round($pictures pecs[1] * $percentage);
    $imagesize = "width=" . $width . " height=" . $height;
  • nice.guy.nige

    #2
    Re: Probably a Silly Code Error

    While the city slept, Marvin (mkantola@excit e.com) feverishly typed...
    [color=blue]
    > 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.[/color]

    A pretty futile exercise, as the user's screen size will not tell you the
    available canvas area of their browser. For example, my display is set to
    1152 x 864, but I very rarely maximise my browser. Even if you could assume
    that everyone had their browser maximised, how would you account for the
    different quantities of toolbars etc that people may or may not be using?

    Cheers,
    Nige

    --
    Nigel Moss
    This is the personal website of Nigel Moss - Web and software developer, musician, photographer. It is home to my CV, portfolio, general info and more.

    Mail address not valid. nigel@DOG.nigen et.org.uk, take the DOG. out!
    In the land of the blind, the one-eyed man is very, very busy!


    Comment

    • Marvin

      #3
      Re: Probably a Silly Code Error

      "nice.guy.n ige" <nigel_moss@dea dspam.com> wrote in
      news:2ph32nFjqq usU1@uni-berlin.de:
      [color=blue]
      > While the city slept, Marvin (mkantola@excit e.com) feverishly typed...
      >[color=green]
      >> 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.[/color]
      >
      > A pretty futile exercise, as the user's screen size will not tell you
      > the available canvas area of their browser. For example, my display is
      > set to 1152 x 864, but I very rarely maximise my browser. Even if you
      > could assume that everyone had their browser maximised, how would you
      > account for the different quantities of toolbars etc that people may
      > or may not be using?
      >
      > Cheers,
      > Nige
      >[/color]

      Well, once it worked I intended to decrease the numbers by 20% or some such
      number to allow for some of the above issues. I don't expect a perfect fit
      for everybody (Or anybody) but for my intended purposes it is not really a
      futile exercise so if anybody has a solution I would appreciate it.
      Marvin

      Comment

      • Virgil Green

        #4
        Re: Probably a Silly Code Error

        "Marvin" <mkantola@excit e.com> wrote in message
        news:Xns9555572 C9912Enoidtoken either@216.196. 97.138...[color=blue]
        > 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.[/color]

        Do you want help working out the algorithm for calculating the height/width
        proportional to a given screen size, or do you want help implementing a
        known algorithm.

        I ask because you can't use javascript to tell php what size to use in an
        IMG tag. If you want the algorithm analyzed, we can help here. If you want
        the process to work (resizing the IMG on the fly) then you need to visit a
        javascript group. I think you can modify the size of the image via
        javascript. Once you know how to do that, then we can help you emit that
        javascript, generating it dynamically to create what you need.

        - Virgil


        Comment

        • Pjotr Wedersteers

          #5
          Re: Probably a Silly Code Error

          Marvin wrote:[color=blue]
          > 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[color=green]
          >>[/color]
          > // xxxxxxxx Get the screen width and set base image size xxx
          > $displayheight = "<SCRIPT language=\"java script\">\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($pictures pecs[0] * $percentage);
          > $height = round($pictures pecs[1] * $percentage);
          > $imagesize = "width=" . $width . " height=" . $height;[/color]

          A) this won't work, you won't get what you want, use Javascript to resize on
          the fly if that's what you need.Don't try this JS and PHP mix for this.
          B) Resized pics look crummy most of the time. Save some different sizes (use
          photoshop or irfanview or whatever) of each picture and have JScript pick
          the one closest to screen size. But as mentioned, many have their browsers
          set to other than full size and your script fails there. It's been tried a
          lot, and mostly it's futile. Without proper indication of the true browser
          size you're lost.

          HTH
          Pjotr


          Comment

          Working...