文章詳情頁(yè)
ASP固定比例裁剪縮略圖的方法
瀏覽:79日期:2022-06-05 11:24:39
一般生成縮略圖的方法有兩種:
第一種:縮放成固定大小的小圖片
第二種:縮放成等比例的小圖片
第一種方法的缺點(diǎn)是,會(huì)使圖片變形,例如一個(gè)身材苗條的MM變成一個(gè)胖MM
第二種方法的缺點(diǎn)是,如果圖片是放在一個(gè)表格中顯示,并且圖片寬高比和這個(gè)表格不同,就不能充滿(mǎn)整個(gè)表格,留下空隙,不好看
這里介紹的方法是“固定比例裁剪”,使用aspjpeg組件,也就是說(shuō),生成的縮略圖寬高比是固定的,但是不會(huì)變形。如果原圖的寬高比大于設(shè)定的寬高比,就會(huì)自動(dòng)剪掉左右兩旁多余的圖;如果原圖的寬高比小于設(shè)定的寬高比,就會(huì)自動(dòng)剪掉上下的多余的圖。
Function MakePic(sourcpic,newwidth,newheight,destpic) On error resume next MakePic=false Set Jpeg = Server.CreateObject(“Persits.Jpeg”) if Err then response.Write (“錯(cuò)誤:空間沒(méi)安裝aspjpeg組件”) response.end end if Jpeg.Quality = 100 Jpeg.Open sourcpic jpeg.PreserveAspectRatio = True ‘等比縮放 if jpeg.OriginalWidth/jpeg.OriginalHeight > newwidth/newheight then"太扁了,要剪掉左右部分 jpeg.Height = newheight jpeg.crop CInt((jpeg.Width – newwidth)/2),0,CInt((jpeg.Width – newwidth)/2)+newwidth,newheight else ‘太高了,要剪掉上下部分 jpeg.Width = newwidth jpeg.crop 0,CInt((jpeg.Height – newheight)/2),newwidth,CInt((jpeg.Height – newheight)/2)+newheight end if Jpeg.Save destpic if err.number=0 then MakePic=True Jpeg.Close Set Jpeg=Nothing End function
以上就是介紹ASP使用aspjpeg固定比例裁剪縮略圖的實(shí)現(xiàn)方法,希望對(duì)大家的學(xué)習(xí)有所幫助。
標(biāo)簽:
ASP
排行榜
