473,388 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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

// 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;
Jul 17 '05 #1
4 1397
While the city slept, Marvin (mk******@excite.com) feverishly typed...
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.


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
http://www.nigenet.org.uk
Mail address not valid. ni***@DOG.nigenet.org.uk, take the DOG. out!
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #2
"nice.guy.nige" <ni********@deadspam.com> wrote in
news:2p************@uni-berlin.de:
While the city slept, Marvin (mk******@excite.com) feverishly typed...
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.


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


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
Jul 17 '05 #3
"Marvin" <mk******@excite.com> wrote in message
news:Xn*****************************@216.196.97.13 8...
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.


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
Jul 17 '05 #4
Marvin wrote:
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;


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
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher Vagnetoft | last post by:
E:\java\projects\console>javac -verbose HelloWorld.java
3
by: Nicke | last post by:
Hi, I've used vb.net for 3 hours(!) now and have probably a very easy question. In my VB6 programs I use For Each Cell in Range... very often which not seems to work in vb.net. Ex. Dim Cell...
1
by: Bkr | last post by:
Gurus, Here is what I ma trying to do. I have numeric expression stored in a table column. for e.g. @a + @b + @c. I supply values to the variables at run time and want them to be computed at run...
3
by: Catweasel | last post by:
I'm new to C++ and have been chucked in at the deep-end. I have a C++ console app that works fine. All I want to do is write to file however as soon as I include the fstream library and try to...
7
by: Matt | last post by:
I've asked this question to some developers that are much more experienced than I, and gotten different answers --- and I can't find anything about it in the documentation. Dim vs. Private as a...
5
by: Control Freq | last post by:
Hi I connect to my MySQL database using MyODBC. I have a table called 'log' in a database called 'home'. When I try to do an insert like this: insert into log (userid,event,event_date) values...
11
by: Sensei | last post by:
Hi again! I have ``yet another silly question'', about arrays this time. I've looked through the FAQs in the array & memory sections without finding an answer. I surely didn't look deep enough. ...
4
by: Marcin Kasprzak | last post by:
Hello Guys, Silly question - what is the most elegant way of compiling a code similar to this one? <code> typedef struct a { b_t *b; } a_t; typedef struct b {
6
by: jeddiki | last post by:
Hi, I am stuck again over something silly that I can not resolve. I am using a link to create a dynamic page. the link is itself written from the same same table that the dynamic page is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.