Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Dynamic Pics
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

asp_storm
Average Member

USA
787 Posts

Posted - 01 July 2001 :  22:36:32  Show Profile  Visit asp_storm's Homepage  Send asp_storm an AOL message
does anyone know how i can write a script or a piece
of code so that when a user clicks on a thumbnail,
it makes a pop-up window with the large pic, w/o
me manually making it?

>—<>—<>—<>—<>—<>—<>—<>—>
"RIGGGHHHTTT"
Thanx,
Ryan
>—<>—<>—<>—<>—<>—<>—<>—<>

aspdesigner
Junior Member

165 Posts

Posted - 02 July 2001 :  02:14:56  Show Profile
[quote]
If you just want to open-up a new browser window, this is real easy. Just do this -


<A HREF="bigpic.jpg" TARGET="_blank"><IMG SRC="smallpic.jpg"></A>


The target= attribute tells the browser what window to open-up the new page in, in this case, it instructs the browser to open the picture in a new browser window.

If you want to have more control over the way the pop-up window looks (i.e. - eliminate the menus, buttons, etc.), you can use Javascript instead. You could do something like this -


<A HREF="bigpic.gif" TARGET="_blank"
onclick="window.open('bigpic.jpg','_blank',
'width=400,height=300,scrollbars=yes');
return false"><IMG SRC="smallpic.jpg"></A>

(Note - above should be all on one line, I broke it up to meake reading it easier.)

This executes the Javascript window.open function to instruct the browser to open-up a new window containing the specified web page (in this case, your big picture)

The last parameter in the window.open function deserves special attention. It is a string containing optional parameters, which allow you to specify things like the window width and height, and whether or not the new window will display things like scroll bars, a menu bar, whether or not the window can be resized, etc. If you do not specify any options, it will open up in default mode, but if you specify any of the window display options (like scrollbars), then ONLY the features you specify will be included in the new window.

The full description of all of the options you can use is too long for here, but can be found in any good reference on Javascript.

Finishing-up the discussion, the "return false" is included to tell the browser not to execute the hyperlink when you click on it (as you have already opened-up the new window via Javascript). The URL and target= in the A tag provide that a window will still open-up, even if the user has Javascript turned-off in their browser.

If all you want to do is open-up a new window with the picture in it, then the first approach is probably easier. If you want to control the size and appearance of the new window, then you should use the Javascript aproach instead.

Hope this was of some help.


Go to Top of Page

asp_storm
Average Member

USA
787 Posts

Posted - 02 July 2001 :  10:10:58  Show Profile  Visit asp_storm's Homepage  Send asp_storm an AOL message
yea it was, but how would i make a[n] asp
script so that there is a template and it
dynamicclly creates the pic in it?


>—<>—<>—<>—<>—<>—<>—<>—>
"RIGGGHHHTTT"
Thanx,
Ryan
>—<>—<>—<>—<>—<>—<>—<>—<>
Go to Top of Page

inworg
Junior Member

Italy
153 Posts

Posted - 02 July 2001 :  11:01:21  Show Profile  Visit inworg's Homepage
In ASP is impossible to create dinamically an image as in a "macro language" or in a template.
But u can do it using PHP + gd (graphics libraries).
Maybe 121host is setting up his servers to do it!!!
Regards

Go to Top of Page

Aznknight
Senior Member

USA
1373 Posts

Posted - 02 July 2001 :  13:01:03  Show Profile  Send Aznknight an AOL message  Send Aznknight an ICQ Message
you can create dynamic pictures in asp with server components like ASPImage.

- Alan
www.iamviet.com
www.calvsa.net
Snitz Resource
Go to Top of Page

big9erfan
Average Member

540 Posts

Posted - 02 July 2001 :  14:03:10  Show Profile
There are ways to do this in ASP without using components like ASPImage, but this will only dynamically change the viewing size of the picture and not the acutal FILE size. So if you have a jpg that is 184k when shown at it's normal size ( lets say 640 x 480 ), it would still be 184k when shown at 64 x 48

Components like ASPImage and such will take care of this problem, acutally creating a smaller file as well.

http://www.ugfl.net/forums
Go to Top of Page

asp_storm
Average Member

USA
787 Posts

Posted - 02 July 2001 :  16:46:42  Show Profile  Visit asp_storm's Homepage  Send asp_storm an AOL message
ok, thanx a lot!

>—<>—<>—<>—<>—<>—<>—<>—>
"RIGGGHHHTTT"
Thanx,
Ryan
>—<>—<>—<>—<>—<>—<>—<>—<>
Go to Top of Page

MorningZ
Junior Member

USA
169 Posts

Posted - 02 July 2001 :  17:05:28  Show Profile  Visit MorningZ's Homepage  Send MorningZ an AOL message
ug, sorry, this is going to be a code intensive post of mine

anyways, here is how to do everything w/o a Third Party Component
( though i 100% agree with the ASPimage thing, it does some very cool stuff )

ok, here we go
first we need some Javascript in the heading

<script language="javascript" type="text/javascript">
<!--
/*
Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
var win = null;
function NewWindow(mypage,myname,w,h,scroll)
{
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}
// -->

<!-- Original: Alex Tu <boudha1@hotmail.com> -->
<!-- Web Site: http://www.geocities.com/MadisonAvenue/4368 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
// End -->
</script>


When this javascript is used, it is going to open a file called "show.asp"

<%@ Language=VBScript %>
<%
'Source for "show.asp"
strPicture = Request.QueryString("pic")
intHeight = Request.QueryString("h")
intWidth = Request.QueryString("w")
%>
<HTML>
<HEAD>
<TITLE>Click Image to Close</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<center>
<a href="javascript:window.close()"><img src="<%= strPicture %>" height=<%= intHeight %> width=<%= intWidth %> alt="Click Picture to Close" border="0"></a><br>
<br>
</center>

</BODY>
</HTML>
%>



Ok, we are done "setting up", now to the your code

We need to get the width and height of the "big" image, figure out the aspect for resizing down to a ThumbNail, and also build the link to the centered pop up window
( i am just making a very general assumption that "/images/" on the root dir is where the images are stored )


'Get Picture Info such as Width and Height
Dim picType, picWidth, picHeight, picName
picName = "thispic.jpg"
Call GetPicFileInfo( Server.MapPath( "/images/" & picName ), picType, picWidth, picHeight )

'Calculate the height and width for the thumbnail ( 75 x 85 max )
if Height > Width then
ThumbHeight = 85
ThumbWidth = cInt(cInt(picWidth) / (cInt(picHeight)/85))
else
ThumbWidth = 75
ThumbHeight = cInt(cInt(picHeight) / (cInt(picWidth)/75))
end if

'Now we build the link
Response.Write "<a href=""/images/show.asp?pic=/images/" & picName & "&w=" & _
picWidth & "&h=" & picHeight & """ onclick=""NewWindow & _
(this.href,'name','" & picWidth + 20 & "','" & picHeight + 20 & "','no');return false"">
'Kinda make a "fake" thumbnail since we dont have a component to make one, and close the link
Response.Write "<img src='/images/" & picName &"' height='" & ThumbHeight & _
"' width='" & ThumbWidth & "' border='0'></a><br>"


Subroutine used to find above width and height

<%
'Heres the Subroutine
Sub GetPicFileInfo( i_sFilename, o_PicType, o_nWidth, o_nHeight )
o_PicType = ""
o_nWidth = 0
o_nHeight = 0

Dim fso, ts
Dim GIF_MARKER, JPG_MARKER

GIF_MARKER = "GIF8"
JPG_MARKER = Chr(&HFF) & Chr(&HD8) & Chr(&HFF) & Chr(&HE0)

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(i_sFilename)

On Error Resume Next
Select Case ts.Read(4)
Case GIF_MARKER
o_PicType = "GIF"
ts.Skip(2)
If Err.Number <> 0 Then
Exit Sub
End If
o_nWidth = Asc(ts.Read(1)) + ( Asc(ts.Read(1))* 256 )
o_nHeight = Asc(ts.Read(1)) + ( Asc(ts.Read(1))* 256 )

Case JPG_MARKER
o_PicType = "JPG"

Dim byteVal, bDone
bDone = False
byteVal = Asc(ts.Read(1))
Do While Not ts.AtEndOfStream And byteVal <> &HD8 And Not bDone
'look for the next marker (xFF)
Do While Not ts.AtEndOfStream And byteVal <> &HFF
byteVal = Asc(ts.Read(1))
Loop

'Get past any repeated xFF markers
Do While Not ts.AtEndOfStream And byteVal = &HFF
byteVal = Asc(ts.Read(1))
Loop

'Check out the marker
'if this is the width/height section then read the values
If ((byteVal >= &HC0) And (byteVal <= &HC3)) Then
ts.Skip(3)
If Err.Number <> 0 Then
Exit Sub
End If
If Not ts.EOF Then
o_nWidth = (Asc(ts.Read(1)) * 256) + Asc(ts.Read(1))
o_nHeight = (Asc(ts.Read(1))* 256) + Asc(ts.Read(1))
bDone = True
End If
Else
'this is a comment or other stuff we are not interested in.
'we must read the size and then skip over this section
Dim nSectionLength
nSectionLength = (Asc(ts.Read(1)) * 256) + Asc(ts.Read(1))

'NOTE: we subtract two since from the size since we already
'are past the length bytes which are included in the size
ts.Skip(nSectionLength - 2)
byteVal = Asc(ts.Read(1))

If Err.Number <> 0 Then
Exit Sub
End If
End If
Loop
End Select

Set ts = Nothing
Set fso = Nothing
End Sub


:: whew ::

i use this very code all over the place, so if you need more help on it, feel free to post again





Edited by - MorningZ on 02 July 2001 17:17:52
Go to Top of Page

big9erfan
Average Member

540 Posts

Posted - 02 July 2001 :  17:16:02  Show Profile
There is some code on 4GuysFromRolla that is very similar to that

I use it simply b/c I don't have access to ASPImage Maybe some day



http://www.ugfl.net/forums
Go to Top of Page

MorningZ
Junior Member

USA
169 Posts

Posted - 02 July 2001 :  17:21:46  Show Profile  Visit MorningZ's Homepage  Send MorningZ an AOL message
quote:
There is some code on 4GuysFromRolla that is very similar to that

i never said it was mine
Go to Top of Page

asp_storm
Average Member

USA
787 Posts

Posted - 02 July 2001 :  17:29:55  Show Profile  Visit asp_storm's Homepage  Send asp_storm an AOL message
can you make the actual page for me? 'cause i am
learning, and would like to see the way i should
set it up?

>—<>—<>—<>—<>—<>—<>—<>—>
"RIGGGHHHTTT"
Thanx,
Ryan
>—<>—<>—<>—<>—<>—<>—<>—<>
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07