Welcome to WebmasterWorld Guest from 54.167.40.25

Forum Moderators: incrediBILL

Message Too Old, No Replies

Resize picture to fit in iframe

iframe resizing for pictures

     

Ricey2005

9:39 am on Jul 27, 2005 (gmt 0)

Inactive Member
Account Expired

 
 


Hi
I have a page and I want to have an iframe centered at the top and below it alot of little images, when I click on the image i want the image to resize to fit the iframe (obviously the image being bigger than the iframe)
Can anyone help
I dont know anything about php or the likes thank you
6:13 pm on July 27, 2005 (gmt 0)

Moderator from US 

WebmasterWorld Administrator travelin_cat is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 28, 2004
posts:3115
votes: 2


Assuming the larger graphic is 200x500, on the page with your iframe put this:

<iframe src="test.html" height="200" width="500"></iframe>

on test.html put this:

<a href="2.gif"><img src="1.gif" border="0"></a>

where 1.gif is the smaller graphic and 2.gif is the 200x500 graphic

When the viewer clicks on 1.gif, 2.gif will pop up filling the iframe beccause the iframe and it are the exact same size....

hope this helps.

2:17 pm on July 28, 2005 (gmt 0)

Full Member

10+ Year Member

joined:July 7, 2003
posts:282
votes: 0


A very efficient way to get the results you're asking for, is to use a bit of server-side scripting. I'll put here a sample in ASP, but this is also doable on php and almost any server-side scripting technology.
Replace the $x, $y, $filename and things like those with the params you need.
The host file (the file where the iframe is):
...
<iframe name="the_frame" height="$y" width="$x"></iframe>
<a href="show_img.asp?fname=$file1.jpg" target="the_frame">
<img src="$file1.jpg" height="$y1" width="$x1" alt="click to enlarge" /> </a>
...
<iframe name="the_frame" height="$y" width="$x"></iframe>
<a href="show_img.asp?fname=$fileN.jpg" target="the_frame">
<img src="$fileN.jpg" height="$yN" width="$xN" alt="click to enlarge" /> </a>

The framed file "show_img.asp":
<%
Dim strFile, strResponse
strFile = Request("fname")
strResponse = "<html><head></head><body>" & vbCrLf
strResponse = strResponse & "<img src=" & Chr(34) & strFile & Chr(34) & _
" height=" & Chr(34) & "$y" & Chr(34) & " width=" & Chr(34) & _
"$x" & Chr(34) & "/>"
strResponse = strResponse & "</body></html>"
%>

The only difficult part is to keep html params "quoted" without these quotes being parsed by the ASP as opening/closing of strings. The call Chr(34) returns a 1-length string with the 34th character in ASCII, which is '"'. Beyond the weird thing of the quotes, I think there is no difficulty on implementing that; even so, if you have any doubt or question, I'll be glad to help you either via reply (generic questions) or sticky mail (if specifics are needed).

Hoping be useful,
Herenvardö