導航:首頁 > 文件處理 > asp網頁壓縮

asp網頁壓縮

發布時間:2024-05-01 07:39:22

Ⅰ asp 實現圖片上傳的時候壓縮

按比例壓縮圖片:

SmallImgFilet = "SmallImg-"&smallname&".jpg" '小圖片指定取名

If IsEmpty(SmallImgFile) then

'dim L as Single , H as Single

Set Jpeg = Server.CreateObject("Persits.Jpeg") '調用組件

Path = Server.MapPath("../") & "\" & BigImgFile '待縮小圖片路徑 放在根目錄 你可以制定文件夾 在../後面
Jpeg.Open Path '打開圖片
L = 120/80'縮略圖高與寬比 你如果只限制寬度就不用下面else的高度比例判斷 只按寬度的對應大圖比例縮小就可以了

H= jpeg.OriginalWidth/jpeg.OriginalHeight

If H > L Then
jpeg.Width = 120
jpeg.Height = (jpeg.OriginalHeight*120)/jpeg.OriginalWidth
Else
jpeg.Height = 80
jpeg.Width = (jpeg.OriginalWidth*80)/jpeg.OriginalHeight
End If
'保存圖片
Jpeg.Save Server.MapPath("../") & "\"&SmallImgFilet'&".jpg"
set Jpeg=nothing
end if

Ⅱ win rar 通過asp。net調用壓縮 如何指定壓縮成zip格式

打開WinRAR主窗口,然後單擊菜單「選項→設置」,在「設置」窗口中選擇「壓縮」選項卡,再單擊「創建默認配置」,在打開的窗口中選擇「壓縮文件格式」為「RAR」,最後「確定」保存設置即可。

Ⅲ asp圖片上傳壓縮小,現在的上傳方法上傳的都是原圖,太大了,訪問速度太慢

給你一個過程你看下
<%
dim arr(3)
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft ''建立上傳對象

formPath="../upImgFile/" '圖片存放的路徑:proct目錄下的uploadimages文件夾 ''在目錄後加(/)

''列出所有上傳了的文件
for each formName in upload.file
set file=upload.file(formName)
if file.filesize>0 then
if file.filesize>10000000 then
response.write "<font size=2>圖片大小超小了限制[<a href=# onclick=history.go(-1)>重新上傳</a>]</font>"
response.end
end if
fileExt=lcase(right(file.filename,4))
if fileExt<>".jpg" then
response.write "<font size=2>文件格式限制[<a href=# onclick=history.go(-1)>請重新上傳</a>]</font>"
response.end
end if
end if

filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName

if file.FileSize>0 then ''如果 FileSize > 0 說明有文件數據
file.SaveAs Server.mappath(formpath&filename) ''保存文件

' 圖片位置
dim PhotoPath
PhotoPath = Server.MapPath(formpath&filename)
'縮小大圖
call OKbigpic(PhotoPath)

'response.write file.FilePath&file.FileName&"("&file.FileSize&") => "&formPath&File.FileName&"上傳成功<br>"
response.write "上傳成功 <a href=# onclick=history.go(-1)>請返回</a>"

end if
set file=nothing
next
set upload=nothing
Response.Write "<script>parent.add.P_url.value='"&FileName&"'</script>"

sub OKbigpic(FileName)
Dim bigpic,bigpicPath,fss
Set bigpic = Server.CreateObject("Persits.Jpeg")
set fss=createobject("scripting.filesystemobject")
' 設置圖片質量
bigpic.Interpolation=2
bigpic.Quality=90
' 圖片位置
if fss.fileExists(FileName) then
bigpic.Open FileName

'下面是按比例縮放
n_MaxWidth=900
n_MaxHeight=1500

'按比例取得縮略圖寬度和高度
Dim n_OriginalWidth, n_OriginalHeight '原圖片寬度、高度
Dim n_BuildWidth, n_BuildHeight '縮略圖寬度、高度
Dim div1, div2
Dim n1, n2
'修改Jpeg
n_OriginalWidth = bigpic.Width
n_OriginalHeight = bigpic.Height
div1 = n_OriginalWidth / n_OriginalHeight
div2 = n_OriginalHeight / n_OriginalWidth
n1 = 0
n2 = 0
If n_OriginalWidth > n_MaxWidth Then
n1 = n_OriginalWidth / n_MaxWidth
Else
n_BuildWidth = n_OriginalWidth
End If
If n_OriginalHeight > n_MaxHeight Then
n2 = n_OriginalHeight / n_MaxHeight
Else
n_BuildHeight = n_OriginalHeight
End If
If n1 <> 0 Or n2 <> 0 Then
If n1 > n2 Then
n_BuildWidth = n_MaxWidth
n_BuildHeight = n_MaxWidth * div2
Else
n_BuildWidth = n_MaxHeight * div1
n_BuildHeight = n_MaxHeight
End If
End If

'指定寬度和高度生成
bigpic.Width = n_BuildWidth
bigpic.Height = n_BuildHeight

' 保存文件
bigpic.Save (FileName)
' 注銷對象
Set bigpic = Nothing

end if
end sub
%>

Ⅳ 關於ASP自動解壓縮 壓縮文件的問題

1、 是不是什麼文件都可以壓縮?
答:壓縮是可以,但有些可執行文件解壓後並不能運行。

可執行程序文件或軟體安裝文件可以壓縮嗎?還是必須放進文件夾里才能壓縮?
答:可執行程序文件可以直接壓縮。
軟體安裝文件必須放進文件夾里壓縮,否則解壓後程序不能正常運行。

2、 一般的壓縮比例是多少?什麼的文件壓縮比例小?小到什麼程度?
答:你用WinRAR軟體,有壓縮比例測試,一目瞭然。

3、 如何製作含有解壓密碼的壓縮文件?
答:打開winrar,選擇你要壓縮的文件,點工具欄上的添加-選擇「高級」選項-設置密碼。

4、 如何破解不知道密碼的壓縮文件?
答:Advanced ZIP Password Recovery 3.52可以解開ZIP壓縮文件的密碼;
Advanced RAR Password Recovery 1.10可以解開RAR壓縮文件的密碼。

5、 除了winrar和winzip外還有哪些常用的壓縮解壓工具?
答:winace

Ⅳ 求asp.net 圖片上傳壓縮圖片大小代碼 就是減小圖片的解析度存儲圖片到伺服器

c#生成圖片縮略圖的類
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

/// <summary>
/// 圖片處理類
/// 1、生成縮略圖片或按照比例改變圖片的大小和畫質
/// 2、將生成的縮略圖放到指定的目錄下
/// </summary>
public class ImageClass
{
public Image ResourceImage;
private int ImageWidth;
private int ImageHeight;

public string ErrMessage;

/// <summary>
/// 類的構造函數
/// </summary>
/// <param name="ImageFileName">圖片文件的全路徑名稱</param>
public ImageClass(string ImageFileName)
{
ResourceImage=Image.FromFile(ImageFileName);
ErrMessage="";
}

public bool ThumbnailCallback()
{
return false;
}

/// <summary>
/// 生成縮略圖重載方法1,返回縮略圖的Image對象
/// </summary>
/// <param name="Width">縮略圖的寬度</param>
/// <param name="Height">縮略圖的高度</param>
/// <returns>縮略圖的Image對象</returns>
public Image GetRecedImage(int Width,int Height)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

RecedImage=ResourceImage.GetThumbnailImage(Width,Height,callb,IntPtr.Zero);

return RecedImage;
}
catch(Exception e)
{
ErrMessage=e.Message;
return null;
}
}

/// <summary>
/// 生成縮略圖重載方法2,將縮略圖文件保存到指定的路徑
/// </summary>
/// <param name="Width">縮略圖的寬度</param>
/// <param name="Height">縮略圖的高度</param>
/// <param name="targetFilePath">縮略圖保存的全文件名,(帶路徑),參數格式:D:Images ilename.jpg</param>
/// <returns>成功返回true,否則返回false</returns>
public bool GetRecedImage(int Width,int Height,string targetFilePath)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

RecedImage=ResourceImage.GetThumbnailImage(Width,Height,callb,IntPtr.Zero);
RecedImage.Save(@targetFilePath,ImageFormat.Jpeg);

RecedImage.Dispose();

return true;
}
catch(Exception e)
{
ErrMessage=e.Message;
return false;
}
}

/// <summary>
/// 生成縮略圖重載方法3,返回縮略圖的Image對象
/// </summary>
/// <param name="Percent">縮略圖的寬度百分比 如:需要百分之80,就填0.8</param>
/// <returns>縮略圖的Image對象</returns>
public Image GetRecedImage(double Percent)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

ImageWidth=Convert.ToInt32(ResourceImage.Width*Percent);
ImageHeight=Convert.ToInt32(ResourceImage.Width*Percent);

RecedImage=ResourceImage.GetThumbnailImage(ImageWidth,ImageHeight,callb,IntPtr.Zero);

return RecedImage;
}
catch(Exception e)
{
ErrMessage=e.Message;
return null;
}
}

/// <summary>
/// 生成縮略圖重載方法4,返回縮略圖的Image對象
/// </summary>
/// <param name="Percent">縮略圖的寬度百分比 如:需要百分之80,就填0.8</param>
/// <param name="targetFilePath">縮略圖保存的全文件名,(帶路徑),參數格式:D:Images ilename.jpg</param>
/// <returns>成功返回true,否則返回false</returns>
public bool GetRecedImage(double Percent,string targetFilePath)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

ImageWidth=Convert.ToInt32(ResourceImage.Width*Percent);
ImageHeight=Convert.ToInt32(ResourceImage.Width*Percent);

RecedImage=ResourceImage.GetThumbnailImage(ImageWidth,ImageHeight,callb,IntPtr.Zero);

RecedImage.Save(@targetFilePath,ImageFormat.Jpeg);

RecedImage.Dispose();

return true;
}
catch(Exception e)
{
ErrMessage=e.Message;
return false;
}
}

}
本篇文章來源於:開發學院 http://e.codepub.com 原文鏈接:http://e.codepub.com/2011/0118/28884.php

Ⅵ asp.net 將原圖用代碼自動壓縮成規定大小後上傳

上傳時候判斷原圖片大小

然後根據大小判斷

  System.Drawing.Image originalImage = System.Drawing.Image.FromStream(file.InputStream);
if (originalImage.Width > 800 || originalImage.Height > 800)

然後規定大小

這問題主要地方是如何獲取圖片的原大小,只要能獲取原大小就能規定格式

閱讀全文

與asp網頁壓縮相關的資料

熱點內容
高一對數的運演算法則及公式 瀏覽:496
壓縮二分之一以上做骨水泥手術 瀏覽:358
伺服器怎麼讓文件可以下載地址 瀏覽:188
加密貨幣2021年市值 瀏覽:838
安卓19怎麼玩俠盜飛車 瀏覽:137
農業經濟學pdf 瀏覽:721
有什麼分享軟體的app 瀏覽:41
電腦文件加密的文件怎麼找出來 瀏覽:87
Java實現sha 瀏覽:525
購物車java代碼 瀏覽:314
windows多核編程 瀏覽:607
股旁網選股指標公式源碼 瀏覽:856
python運維管理工具 瀏覽:453
功率分配演算法 瀏覽:489
錢豆豆app可以做什麼 瀏覽:194
騰訊雲伺服器還需要資料庫嗎 瀏覽:767
比較器編程 瀏覽:738
蘋果賞金賽和平精英是什麼app 瀏覽:986
idea查找項目所在文件夾 瀏覽:163
程序員的電腦硬碟清理 瀏覽:686