标题:[求助]老问题~~斑竹~~
只看楼主
滚水六脚
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2004-8-16
 问题点数:0 回复次数:15 
[求助]老问题~~斑竹~~

图片缩略图的问题:我已经下载了ASPJPEG组件,而且已经做出了缩略图~~

但到最后要上传才知道,经理不让我们在服务器上安装该组件~~~

请问有办法解决吗?

我看到一的图片管理系统上可以在图片上传时读取图片长宽,除此外还有别的方法吗?毕竟该数据库麻烦~~

搜索更多相关主题的帖子: 斑竹 
2004-08-20 09:25
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

读图片宽度太简单了


天津网站建设 http://www./
2004-08-20 14:03
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 
<!--一下代码由griefforyou编写-->
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="px12">
<tr>
  <td height="25"> <font color="#FF0000"><b><br>
 注意:</b></font>上传图片须为jpg或gif格式,图片大小须小于200k。<br>        </td>
</tr>
<tr>
  <td height="12">
 <form name="form1" method="post" action="upload.asp" enctype="multipart/form-data" onSubmit="javascript:return checksubmit();">
   <b><font size="2">请选择图片:</font></b>
   <input type=file name="file1" onKeyDown="JavaScript:return(false);" onpropertychange="JavaScript:ShowImg(this.value);">
   <script language="vbScript">
  function checksubmit()
   if form1.file1.value<>"" then
    if mid(lcase(form1.file1.value),instrrev(form1.file1.value,"."))<>".gif" and mid(lcase(form1.file1.value),instrrev(form1.file1.value,"."))<>".jpg" then
     alert("图片格式错误,请重新选择!")
     checksubmit=false
     exit function
    else
     checksubmit=true
    end if
   else
    alert("请选择要上传的图片!")
    checksubmit=false
    exit function
   end if
  end function
  </script>
   <input type=submit name="Submit" value="上传该图片" >
   <input type="hidden" name="photoid" value="">
 </form></td>
</tr>
<tr>
 <td height="13"> 图片预览:
  <script language="JavaScript">
  function ShowImg(src)
  {
   document.all("imgDiv").innerHTML="<img id='imgObj' onerror='JavaScript:GetError()' onload='JavaScript:GetSize()' src='" + src + "'>";
  }
  function GetSize()
  {
   document.all("imgSize").innerHTML="图片大小(宽×高):<font color=red>" + document.all("imgObj").width + "×" + document.all("imgObj").height + "</font>";
  }
  function GetError()
  {
   document.all("imgSize").innerHTML="<font color=red>图片格式错误!</font>";   
   document.all("imgDiv").innerHTML="";
   alert("图片格式错误!");
  }   
  </script>
  <br>
  <span id="imgSize"></span>
  <div id="imgDiv">
  </div>   
  </td>
</tr>
</table>

天津网站建设 http://www./
2004-08-20 14:07
滚水六脚
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2004-8-16
得分:0 

救命啊,又是JAVASCRIPT,看不明白啊~~~~

能换ASP吗?

2004-08-20 14:54
滚水六脚
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2004-8-16
得分:0 
前面那个看懂了,后面那JAVASCRIPT看不懂,想改都难~~,,谢谢~

[此贴子已经被作者于2004-08-20 15:04:17编辑过]


2004-08-20 14:56
滚水六脚
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2004-8-16
得分:0 

document.all("imgObj").width 应该是写出图片宽度,但imagobj是怎么来的?JAVASCRIPT自带的吗?

还有src='" + src + "' 中的" + src + " 在那里有读取的功能?它相当于request.from("")吗?

2004-08-20 15:20
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

晕。。。。。。。。

你要ASP读图片宽度呀


天津网站建设 http://www./
2004-08-20 15:41
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

<% ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::: BMP, GIF, JPG and PNG ::: ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::: ::: ''::: This function gets a specified number of bytes from any ::: ''::: file, starting at the offset (base 1) ::: ''::: ::: ''::: Passed: ::: ''::: flnm => Filespec of file to read ::: ''::: offset => Offset at which to start reading ::: ''::: bytes => How many bytes to read ::: ''::: ::: ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function GetBytes(flnm, offset, bytes) Dim objFSO Dim objFTemp Dim objTextStream Dim lngSize on error resume next Set objFSO = CreateObject("Scripting.FileSystemObject")

'' First, we get the filesize Set objFTemp = objFSO.GetFile(flnm) lngSize = objFTemp.Size set objFTemp = nothing fsoForReading = 1 Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading) if offset > 0 then strBuff = objTextStream.Read(offset - 1) end if if bytes = -1 then '' Get All! GetBytes = objTextStream.Read(lngSize) ''ReadAll else GetBytes = objTextStream.Read(bytes) end if objTextStream.Close set objTextStream = nothing set objFSO = nothing end function

''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::: ::: ''::: Functions to convert two bytes to a numeric value (long) ::: ''::: (both little-endian and big-endian) ::: ''::: ::: ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function lngConvert(strTemp) lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256))) end function function lngConvert2(strTemp) lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256))) end function

''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::: ::: ''::: This function does most of the real work. It will attempt ::: ''::: to read any file, regardless of the extension, and will ::: ''::: identify if it is a graphical image. ::: ''::: ::: ''::: Passed: ::: ''::: flnm => Filespec of file to read ::: ''::: width => width of image ::: ''::: height => height of image ::: ''::: depth => color depth (in number of colors) ::: ''::: strImageType=> type of image (e.g. GIF, BMP, etc.) ::: ''::: ::: ''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function gfxSpex(flnm, width, height, depth, strImageType) dim strPNG dim strGIF dim strBMP dim strType strType = "" strImageType = "(unknown)" gfxSpex = False strPNG = chr(137) & chr(80) & chr(78) strGIF = "GIF" strBMP = chr(66) & chr(77) strType = GetBytes(flnm, 0, 3) if strType = strGIF then '' is GIF strImageType = "GIF" Width = lngConvert(GetBytes(flnm, 7, 2)) Height = lngConvert(GetBytes(flnm, 9, 2)) Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1) gfxSpex = True elseif left(strType, 2) = strBMP then '' is BMP strImageType = "BMP" Width = lngConvert(GetBytes(flnm, 19, 2)) Height = lngConvert(GetBytes(flnm, 23, 2)) Depth = 2 ^ (asc(GetBytes(flnm, 29, 1))) gfxSpex = True elseif strType = strPNG then '' Is PNG strImageType = "PNG" Width = lngConvert2(GetBytes(flnm, 19, 2)) Height = lngConvert2(GetBytes(flnm, 23, 2)) Depth = getBytes(flnm, 25, 2) select case asc(right(Depth,1)) case 0 Depth = 2 ^ (asc(left(Depth, 1))) gfxSpex = True case 2 Depth = 2 ^ (asc(left(Depth, 1)) * 3) gfxSpex = True case 3 Depth = 2 ^ (asc(left(Depth, 1))) ''8 gfxSpex = True case 4 Depth = 2 ^ (asc(left(Depth, 1)) * 2) gfxSpex = True case 6 Depth = 2 ^ (asc(left(Depth, 1)) * 4) gfxSpex = True case else Depth = -1 end select

else strBuff = GetBytes(flnm, 0, -1) '' Get all bytes from file lngSize = len(strBuff) flgFound = 0 strTarget = chr(255) & chr(216) & chr(255) flgFound = instr(strBuff, strTarget) if flgFound = 0 then exit function end if strImageType = "JPG" lngPos = flgFound + 2 ExitLoop = false do while ExitLoop = False and lngPos < lngSize

do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize lngPos = lngPos + 1 loop if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2)) lngPos = lngPos + lngMarkerSize + 1 else ExitLoop = True end if loop '' if ExitLoop = False then Width = -1 Height = -1 Depth = -1 else Height = lngConvert2(mid(strBuff, lngPos + 4, 2)) Width = lngConvert2(mid(strBuff, lngPos + 6, 2)) Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8) gfxSpex = True end if

end if end function

''::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''::: Test Harness ::: '':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

'' To test, we''ll just try to show all files with a .GIF extension in the root of C: Set objFSO = CreateObject("Scripting.FileSystemObject") Set objF = objFSO.GetFolder("D:\") Set objFC = objF.Files response.write "<table border=""0"" cellpadding=""5"">" For Each f1 in objFC if instr(ucase(f1.Name), ".GIF") then response.write "<tr><td>" & f1.name & "</td><td>" & f1.DateCreated & "</td><td>" & f1.Size & "</td><td>" if gfxSpex(f1.Path, w, h, c, strType) = true then response.write w & " x " & h & " " & c & " colors" else response.write " " end if response.write "</td></tr>" end if Next response.write "</table>" set objFC = nothing set objF = nothing set objFSO = nothing

%>


天津网站建设 http://www./
2004-08-20 15:47
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

http://dev.csdn.net/develop/article/14/14980.shtm

通过Adodb.Stream取得图像(BMP JPG PNG GIF SWF)的高度和宽度 qiushuiwuhen [原作]

上传图片或显示SWF的时候都希望得到它的高度和宽度

基本原理使用Adodb.Stream读二进制文件然后进行解析,然后返回一数组 第一个元素为类型(BMP JPG PNG GIF SWF) 第二个元素为宽度{width} 第三个元素为高度{height} 第四个元素为width={width},height={height}式字符串

Class qswhImg dim aso Private Sub Class_Initialize set aso=CreateObject("Adodb.Stream") aso.Mode=3 aso.Type=1 aso.Open End Sub Private Sub Class_Terminate set aso=nothing End Sub

Private Function Bin2Str(Bin) Dim I, Str For I=1 to LenB(Bin) clow=MidB(Bin,I,1) if ASCB(clow)<128 then Str = Str & Chr(ASCB(clow)) else I=I+1 if I <= LenB(Bin) then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow)) end if Next Bin2Str = Str End Function Private Function Num2Str(num,base,lens) 'qiushuiwuhen (2002-8-12) dim ret ret = "" while(num>=base) ret = (num mod base) & ret num = (num - num mod base)/base wend Num2Str = right(string(lens,"0") & num & ret,lens) End Function Private Function Str2Num(str,base) 'qiushuiwuhen (2002-8-12) dim ret ret = 0 for i=1 to len(str) ret = ret *base + cint(mid(str,i,1)) next Str2Num=ret End Function Private Function BinVal(bin) 'qiushuiwuhen (2002-8-12) dim ret ret = 0 for i = lenb(bin) to 1 step -1 ret = ret *256 + ascb(midb(bin,i,1)) next BinVal=ret End Function Private Function BinVal2(bin) 'qiushuiwuhen (2002-8-12) dim ret ret = 0 for i = 1 to lenb(bin) ret = ret *256 + ascb(midb(bin,i,1)) next BinVal2=ret End Function Function getImageSize(filespec) 'qiushuiwuhen (2002-9-3) dim ret(3) aso.LoadFromFile(filespec) bFlag=aso.read(3) select case hex(binVal(bFlag)) case "4E5089": aso.read(15) ret(0)="PNG" ret(1)=BinVal2(aso.read(2)) aso.read(2) ret(2)=BinVal2(aso.read(2)) case "464947": aso.read(3) ret(0)="GIF" ret(1)=BinVal(aso.read(2)) ret(2)=BinVal(aso.read(2)) case "535746": aso.read(5) binData=aso.Read(1) sConv=Num2Str(ascb(binData),2 ,8) nBits=Str2Num(left(sConv,5),2) sConv=mid(sConv,6) while(len(sConv)<nBits*4) binData=aso.Read(1) sConv=sConv&Num2Str(ascb(binData),2 ,8) wend ret(0)="SWF" ret(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid(sConv,0*nBits+1,nBits),2))/20) ret(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid(sConv,2*nBits+1,nBits),2))/20) case "FFD8FF": do d p1=binVal(aso.Read(1)): loop while p1=255 and not aso.EOS if p1>191 and p1<196 then exit do else aso.read(binval2(aso.Read(2))-2) dp1=binVal(aso.Read(1)):loop while p1<255 and not aso.EOS loop while true aso.Read(3) ret(0)="JPG" ret(2)=binval2(aso.Read(2)) ret(1)=binval2(aso.Read(2)) case else: if left(Bin2Str(bFlag),2)="BM" then aso.Read(15) ret(0)="BMP" ret(1)=binval(aso.Read(4)) ret(2)=binval(aso.Read(4)) else ret(0)="" end if end select ret(3)="width=""" & ret(1) &""" height=""" & ret(2) &"""" getimagesize=ret End Function End Class

使用范例(读某目录下所有图片的宽度): set qswh=new qswhImg

Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(server.mappath(".")) Set fc = f.Files For Each f1 in fc ext=fso.GetExtensionName(f1.path) select case ext case "gif","bmp","jpg","png": arr=qswh.getImageSize(f1.path) response.write "<br>" & arr(0) & " " & arr(3) & ":" & f1.name & " width:" & arr(1) & " height:" & arr(2) case "swf" arr=qswh.getimagesize(f1.path) response.write "<br>" & arr(0) & " " & arr(3) & ":" & f1.name & " width:" & arr(1) & " height:" & arr(2) end select Next Set fc=nothing Set f=nothing Set fso=nothing Set qswh=nothing

现该文章仅限在CSDN文档中心发表,若需要转载,请和作者联系,谢谢。

作者Blog:http://blog.csdn.net/qiushuiwuhen/

天津网站建设 http://www./
2004-08-20 15:48
滚水六脚
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2004-8-16
得分:0 

先谢谢斑竹

那还有没有在上传时把图片长宽读入数据库的代码啊? 谢谢~~

2004-08-21 11:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-4442-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.109161 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved