![]() |
|
![]() | ||
|
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> "); } } ?> 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 |
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
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> "); } } 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> "); 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> "); } } |
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 Home - Answers FAQ - Terms of Service - Privacy Policy |