Google Answers Logo
View Question
 
Q: Javascript / PHP - Image ( No Answer,   2 Comments )
Question  
Subject: Javascript / PHP - Image
Category: Computers
Asked by: billkellaway-ga
List Price: $5.00
Posted: 14 Apr 2005 11:54 PDT
Expires: 14 May 2005 11:54 PDT
Question ID: 509266
Javascript / PHP - I am trying to use Javascript and PHP to rotate
images via a link.  I have a function that I have modified so that I
can pass the image height and width.  Here's my function -
function imgRotateHW(imgName,height,width)
{
	 document.images.one.src = 'img/'+imgName;
	 document.images.one.height = height; 
	 document.images.one.width = width;
}

Here's the PHP that I am passing it to .. 

<?php //for ($i = 0 ; $i < count($resPPH); $i++)   {  
if (count($resPPH) > 1) {
for($t = 0; $t < count($resPPH); $t++) {
/* Get the width and height of the image ... */
list($width, $height) =
getimagesize($_SERVER['DOCUMENT_ROOT'].'/img/'.$resPPH[$t][photo_name]);
/* Compute the aspect ratio  ... */
$imageHWAspecRatio = ($height/$width);
print  ("<a href=\"#\"
onClick=\"imgRotateHW('t".$resPPH[$t][photo_name].",".$height.",".$width."')\">");
print (($t+1)."</a>&nbsp;"); 
	}
}
?>

I want to know if I can assign the image height and width with
Javascript.  I know what these values are .. I can successfully
manipulate these values with PHP but want to know how I can pass them
to Javascript in a useful way.

Thanks, 

Bill Kellaway
Answer  
There is no answer at this time.

Comments  
Subject: Re: Javascript / PHP - Image
From: jemtallon-ga on 14 Apr 2005 15:12 PDT
 
Actually, you very nearly had it already, if I understand your
question, asside from a few errors in your PHP.

You may want to rewrite your PHP to something like this and try it again:

if (count($resPPH) > 1) {
for($t = 0; $t < count($resPPH); $t++) {
/* Get the width and height of the image ... */
list($width, $height) =
getimagesize($_SERVER['DOCUMENT_ROOT'].'/img/'.$resPPH[$t][photo_name]);

/* Compute the aspect ratio (only is we aren't dividing by zero) ... */
if ($width!=0)
$imageHWAspecRatio = ($height/$width);
else
$imageHWAspecRatio = 0;

/* Uncomment this to give it a test!
width=500;
height=500;
*/

/* Note that I moved the last single-quote character to before the
first comma. Before you were sending the image name, height, and width
as one long string and javascript was treating it as an image name. */
print  ("<a href=\"#\"
onClick=\"imgRotateHW('t".$resPPH[$t][photo_name]."',".$height.",".$width.")\">");
print (($t+1)."</a>&nbsp;"); 
	}
}

Hope this helps you!

Sincerely,
Jem Tallon
Subject: Re: Javascript / PHP - Image
From: jemtallon-ga on 14 Apr 2005 15:16 PDT
 
My appologies. I forgot to put $ signs before the height and width in
the examples and remove the t from the beginning of the line:

onClick=\"imgRotateHW('t".$resPPH[$t][photo_name]."',".$height.",".$width.")\">");
print (($t+1)."</a>&nbsp;");

The real fix should be the following:

f (count($resPPH) > 1) {
for($t = 0; $t < count($resPPH); $t++) {
/* Get the width and height of the image ... */
list($width, $height) =
getimagesize($_SERVER['DOCUMENT_ROOT'].'/img/'.$resPPH[$t][photo_name]);

/* Compute the aspect ratio (only is we aren't dividing by zero) ... */
if ($width!=0)
$imageHWAspecRatio = ($height/$width);
else
$imageHWAspecRatio = 0;

/* Uncomment this to give it a test!
$width=500;
$height=500;
*/

/* Note that I moved the last single-quote character to before the
first comma. Before you were sending the image name, height, and width
as one long string and javascript was treating it as an image name. */
print  ("<a href=\"#\"
onClick=\"imgRotateHW('".$resPPH[$t][photo_name]."',".$height.",".$width.")\">");
print (($t+1)."</a>&nbsp;"); 
	}
}

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy