服务器之家

服务器之家 > 正文

ASPJPEG综合操作的CLASS类

时间:2019-10-08 09:46     来源/作者:asp教程网
  1. <%   
  2. 'ASPJPEG综合操作CLASS   
  3. Class AspJpeg   
  4. Dim AspJpeg_Obj,obj   
  5. Private Img_MathPath_From,Img_MathPath_To,Img_Reduce_Size,CoverIf   
  6. Private Img_Frame_Size,Img_Frame_Color,Img_Frame_Solid,Img_Frame_Width,Img_Frame_Height   
  7. Private Img_Font_Content,Img_Font_Family,Img_Font_Color,Img_Font_Quality,Img_Font_Size,Img_Font_Bold,Img_Font_X,Img_Font_Y   
  8. Private Img_PicIn_Path,Img_PicIn_X,Img_PicIn_Y   
  9. '--------------取原文件路径   
  10. Public Property Let MathPathFrom(StrType)   
  11. Img_MathPath_From=StrType   
  12. End Property   
  13.  
  14. '--------------取文件保存路径   
  15. Public Property Let MathPathTo(strType)   
  16. Img_MathPath_To=strType   
  17. End Property   
  18.  
  19. '--------------保存文件时是否覆盖已有文件   
  20. Public Property Let CovePro(LngSize)   
  21. If LngSize=0 or LngSize=1 or LngSize=true or LngSize=false then   
  22. CoverIf=LngSize   
  23. End If   
  24. End Property   
  25.  
  26. '---------------取缩略图/放大图 缩略值   
  27. Public Property Let ReduceSize(LngSize)   
  28. If isNumeric(LngSize) then   
  29. Img_Reduce_Size=LngSize   
  30. End If   
  31. End Property   
  32.  
  33. '---------------取描边属性   
  34. '边框粗细   
  35. Public Property Let FrameSize(LngSize)   
  36. If isNumeric(LngSize) then   
  37. Img_Frame_Size=Clng(LngSize)   
  38. End If   
  39. End Property   
  40. '边框宽度   
  41. Public Property Let FrameWidth(LngSize)   
  42. If isNumeric(LngSize) then   
  43. Img_Frame_Width=Clng(LngSize)   
  44. End If   
  45. End Property   
  46. '边框高度   
  47. Public Property Let FrameHeight(LngSize)   
  48. If isNumeric(LngSize) then   
  49. Img_Frame_Height=Clng(LngSize)   
  50. End If   
  51. End Property   
  52. '边框颜色   
  53. Public Property Let FrameColor(strType)   
  54. If strType<>"" then   
  55. Img_Frame_Color=strType   
  56. End If   
  57. End Property   
  58. '边框是否加粗   
  59. Public Property Let FrameSolid(LngSize)   
  60. If LngSize=1 or LngSize=0 or LngSize=true or LngSize=false then   
  61. Img_Frame_Solid=LngSize   
  62. End If   
  63. End Property   
  64.  
  65. '---------------取插入文字属性   
  66. '插入的文字   
  67. Public Property Let Content(strType)   
  68. If strType<>"" then   
  69. Img_Font_Content=strType   
  70. End If   
  71. End Property   
  72. '文字字体   
  73. Public Property Let FontFamily(strType)   
  74. If strType<>"" then   
  75. Img_Font_Family=strType   
  76. End If   
  77. End Property   
  78. '文字颜色   
  79. Public Property Let FontColor(strType)   
  80. If strType<>"" then   
  81. Img_Font_Color=strType   
  82. End If   
  83. End Property   
  84. '文字品质   
  85. Public Property Let FontQuality(LngSize)   
  86. If isNumeric(LngSize) then   
  87. Img_Font_Quality=Clng(LngSize)   
  88. End If   
  89. End Property   
  90. '文字大小   
  91. Public Property Let FontSize(LngSize)   
  92. If isNumeric(LngSize) then   
  93. Img_Font_Size=Clng(LngSize)   
  94. End If   
  95. End Property   
  96. '文字是否加粗   
  97. Public Property Let FontBold(LngSize)   
  98. If LngSize=1 or LngSize=0 or LngSize=true or LngSize=false then   
  99. Img_Font_Bold=LngSize   
  100. End If   
  101. End Property   
  102. '输入文字的X坐标   
  103. Public Property Let FontX(LngSize)   
  104. If isNumeric(LngSize) then   
  105. Img_Font_X=Clng(LngSize)   
  106. End If   
  107. End Property   
  108. '输入文字的Y坐标   
  109. Public Property Let FontY(LngSize)   
  110. If isNumeric(LngSize) then   
  111. Img_Font_Y=Clng(LngSize)   
  112. End If   
  113. End Property   
  114.  
  115. '---------------取插入图片属性   
  116. '插入图片的路径   
  117. Public Property Let PicInPath(strType)   
  118. Img_PicIn_Path=strType   
  119. End Property   
  120. '图片插入的X坐标   
  121. Public Property Let PicInX(LngSize)   
  122. If isNumeric(LngSize) then   
  123. Img_PicIn_X=Clng(LngSize)   
  124. End If   
  125. End Property   
  126. '图片插入的Y坐标   
  127. Public Property Let PicInY(LngSize)   
  128. If isNumeric(LngSize) then   
  129. Img_PicIn_Y=Clng(LngSize)   
  130. End If   
  131. End Property   
  132.  
  133.  
  134. Private Sub Class_Initialize()   
  135. Set AspJpeg_Obj=createObject("Persits.Jpeg")   
  136. Img_MathPath_From=""   
  137. Img_MathPath_To=""   
  138. Img_Reduce_Size=150   
  139. Img_Frame_Size=1   
  140. 'Img_Frame_Width=0   
  141. 'Img_Frame_Height=0   
  142. 'Img_Frame_Color="&H000000"   
  143. 'Img_Frame_Bold=false   
  144. Img_Font_Content="GoldenLeaf"   
  145. 'Img_Font_Family="Arial"   
  146. 'Img_Font_Color="&H000000"   
  147. Img_Font_Quality=3   
  148. Img_Font_Size=14   
  149. 'Img_Font_Bold=False   
  150. Img_Font_X=10   
  151. Img_Font_Y=5   
  152. 'Img_PicIn_X=0   
  153. 'Img_PicIn_Y=0   
  154. CoverIf=1   
  155.  
  156. End Sub   
  157. Private Sub Class_Terminate()   
  158. Err.Clear   
  159. Set AspJpeg_Obj=Nothing   
  160. End Sub   
  161. '判断文件是否存在   
  162. Private Function FileIs(path)   
  163. Set fsos=Server.createObject("Scripting.FileSystemObject")   
  164. FileIs=fsos.FileExists(path)   
  165. Set fsos=Nothing   
  166. End Function   
  167.  
  168. '判断目录是否存在   
  169. Private Function FolderIs(path)   
  170. Set fsos=Server.createObject("Scripting.FileSystemObject")   
  171. FolderIs=fsos.FolderExists(path)   
  172. Set fsos=Nothing   
  173. End Function   
  174. '*******************************************   
  175. '函数作用:取得当前文件的上一级路径   
  176. '*******************************************   
  177. Private Function UpDir(ByVal D)   
  178. If Len(D) = 0 then   
  179. UpDir=""   
  180. Else   
  181. UpDir=Left(D,InStrRev(D,"\")-1)   
  182. End If   
  183. End Function   
  184.  
  185. Private Function Errors(Errors_id)   
  186. select Case Errors_id   
  187. Case "0"   
  188. Errors="指定文件不存在"   
  189. Case 1   
  190. Errors="指定目录不存在"   
  191. Case 2   
  192. Errors="已存在相同名称文件"   
  193. Case 3   
  194. Errors="参数溢出"   
  195. End select   
  196. End Function   
  197.  
  198.  
  199. '取图片宽度   
  200. Public Function ImgInfo_Width(Img_MathPath)   
  201. If Not(FileIs(Img_MathPath)) then   
  202. 'Exit Function   
  203. ImgInfo_Width=Errors(0)   
  204. Else   
  205. AspJpeg_Obj.Open Img_MathPath   
  206. ImgInfo_Width=AspJpeg_Obj.width   
  207. End If   
  208. End Function   
  209. '取图片高度   
  210. Public Function ImgInfo_Height(Img_MathPath)   
  211. If Not(FileIs(Img_MathPath)) then   
  212. 'Exit Function   
  213. ImgInfo_Height=Errors(0)   
  214. Else   
  215. AspJpeg_Obj.Open Img_MathPath   
  216. ImgInfo_Height=AspJpeg_Obj.height   
  217. End If   
  218. End Function   
  219. '生成缩略图/放大图   
  220. Public Function Img_Reduce()   
  221. If Not(FileIs(Img_MathPath_From)) then   
  222. Img_Reduce=Errors(0)   
  223. Exit Function   
  224. End If   
  225. If Not(FolderIs(UpDir(Img_MathPath_To))) then   
  226. Img_Reduce=Errors(1)   
  227. Exit Function   
  228. End If   
  229. If CoverIf=0 or CoverIf=False then   
  230. If FileIs(Img_MathPath_To) then   
  231. Img_Reduce=Errors(2)   
  232. Exit Function   
  233. End If   
  234. End If   
  235. AspJpeg_Obj.Open Img_MathPath_From   
  236. AspJpeg_Obj.PreserveAspectRatio = True   
  237. If AspJpeg_Obj.OriginalWidth>AspJpeg_Obj.OriginalHeight Then   
  238. AspJpeg_Obj.Width=Img_Reduce_Size   
  239. Else   
  240. AspJpeg_Obj.Height=Img_Reduce_Size   
  241. End If   
  242. If AspJpeg_Obj.OriginalWidth>Img_Reduce_Size or AspJpeg_Obj.OriginalHeight>Img_Reduce_Size Then   
  243. If AspJpeg_Obj.Width<Img_Reduce_Size or AspJpeg_Obj.Height<Img_Reduce_Size then   
  244. Set AspJpeg_Obj_New=createObject("Persits.Jpeg")   
  245. AspJpeg_Obj_New.new Img_Reduce_Size,Img_Reduce_Size,&HFFFFFF   
  246. AspJpeg_Obj_New.DrawImage (150-AspJpeg_Obj.width)/2,(150-AspJpeg_Obj.height)/2,AspJpeg_Obj   
  247. If Img_Frame_Size>0 then   
  248. Call Img_Pen(AspJpeg_Obj_New)   
  249. End If   
  250. If Img_Font_Content<>"" then   
  251. Img_Font_X=AspJpeg_Obj_New.Width/2   
  252. Img_Font_Y=AspJpeg_Obj_New.Height-15   
  253. Call Img_Font(AspJpeg_Obj_New)   
  254. End If   
  255. AspJpeg_Obj_New.Sharpen 1, 130   
  256. AspJpeg_Obj_New.Save Img_MathPath_To   
  257. Set AspJpeg_Obj_New=Nothing   
  258. Else   
  259. If Img_Frame_Size>0 then   
  260. Call Img_Pen(AspJpeg_Obj)   
  261. End If   
  262. If Img_Font_Content<>"" then   
  263. Img_Font_X=AspJpeg_Obj.Width/2   
  264. Img_Font_Y=AspJpeg_Obj.Height-15   
  265. Call Img_Font(AspJpeg_Obj)   
  266. End If   
  267. AspJpeg_Obj.Sharpen 1, 130   
  268. AspJpeg_Obj.Save Img_MathPath_To   
  269. End If   
  270. Else   
  271. If Img_Frame_Size>0 then   
  272. Call Img_Pen(AspJpeg_Obj)   
  273. End If   
  274. If Img_Font_Content<>"" then   
  275. Img_Font_X=AspJpeg_Obj.Width/2   
  276. Img_Font_Y=AspJpeg_Obj.Height-15   
  277. Call Img_Font(AspJpeg_Obj)   
  278. End If   
  279. AspJpeg_Obj.Sharpen 1, 130   
  280. AspJpeg_Obj.Save Img_MathPath_To   
  281. End If   
  282. End Function   
  283. '生成水印   
  284. Public Function Img_WaterMark()   
  285. If Not(FileIs(Img_MathPath_From)) then   
  286. Img_WaterMark=Errors(0)   
  287. Exit Function   
  288. End If   
  289. If Img_MathPath_To="" then   
  290. Img_MathPath_To=Img_MathPath_From   
  291. ElseIf Not(FolderIs(UpDir(Img_MathPath_To))) then   
  292. Img_WaterMark=Errors(1)   
  293. Exit Function   
  294. End If   
  295. If CoverIf=0 or CoverIf=false then   
  296. If Img_MathPath_To<>Img_MathPath_From and FileIs(Img_MathPath_To) then   
  297. Img_WaterMark=Errors(2)   
  298. Exit Function   
  299. End If   
  300. End If   
  301. AspJpeg_Obj.Open Img_MathPath_From   
  302. If Img_PicIn_Path<>"" then   
  303. If Not(FileIs(Img_PicIn_Path)) then   
  304. Img_WaterMark=Errors(0)   
  305. Exit Function   
  306. End If   
  307. Set AspJpeg_Obj_New=createObject("Persits.Jpeg")   
  308. AspJpeg_Obj_New.Open Img_PicIn_Path   
  309. AspJpeg_Obj.PreserveAspectRatio = True   
  310. AspJpeg_Obj_New.PreserveAspectRatio = True   
  311. If AspJpeg_Obj.OriginalWidth<Img_Reduce_Size or AspJpeg_Obj.OriginalHeight<Img_Reduce_Size then   
  312. Img_WaterMark=Errors(3)   
  313. Exit Function   
  314. End If   
  315. If AspJpeg_Obj_New.OriginalWidth>AspJpeg_Obj_New.OriginalHeight Then   
  316. AspJpeg_Obj_New.Width=Img_Reduce_Size   
  317. Else   
  318. AspJpeg_Obj_New.Height=Img_Reduce_Size   
  319. End If   
  320. If Img_PicIn_X="" then Img_PicIn_X=AspJpeg_Obj.Width-AspJpeg_Obj_New.Width   
  321. If Img_PicIn_Y="" then Img_PicIn_Y=AspJpeg_Obj.Height-AspJpeg_Obj_New.Height   
  322. AspJpeg_Obj.DrawImage Img_PicIn_X,Img_PicIn_Y,AspJpeg_Obj_New   
  323. Set AspJpeg_Obj_New=Nothing   
  324. End If   
  325. If Img_Frame_Size>0 then   
  326. Call Img_Pen(AspJpeg_Obj)   
  327. End If   
  328. If Img_Font_Content<>"" then   
  329. Call Img_Font(AspJpeg_Obj)   
  330. End If   
  331. 'AspJpeg_Obj.Sharpen 1, 130   
  332. AspJpeg_Obj.Save Img_MathPath_To   
  333. End Function   
  334. '生成框架   
  335. Private Function Img_Pen(Obj)   
  336. If Img_Frame_Width=0 then Img_Frame_Width=Obj.Width   
  337. If Img_Frame_Height=0 then Img_Frame_Height=Obj.Height   
  338. Obj.Canvas.Pen.Color = Img_Frame_Color   
  339. Obj.Canvas.Pen.Width = Img_Frame_Size   
  340. Obj.Canvas.Brush.Solid = Img_Frame_Solid   
  341. Obj.Canvas.Bar 1,1,Img_Frame_Width,Img_Frame_Height   
  342. End Function   
  343. '生成水印字   
  344. Private Function Img_Font(Obj)   
  345. Obj.Canvas.Font.Color = Img_Font_Color   
  346. Obj.Canvas.Font.Family = Img_Font_Family   
  347. Obj.Canvas.Font.Quality=Img_Font_Quality   
  348. Obj.Canvas.Font.Size=Img_Font_Size   
  349. Obj.Canvas.Font.Bold = Img_Font_Bold   
  350. Obj.Canvas.Print Img_Font_X,Img_Font_Y,Img_Font_Content   
  351. End Function   
  352. End Class   
  353. %>   


这个类可以公开调用  
1. ImgInfo_Height 取图片高度  
2. ImgInfo_Width 取图片宽度  
调用方法:  

复制代码代码如下:


Dim NewObj,Pic_h,Pic_w   
Set NewObj=New AspJpeg   
Pic_h=NewObj.ImgInfo_Height("f:/test.jpg")   
Pic_w=NewObj.ImgInfo_Width("f:/test.jpg")   
Set NewObj=Nothing   
Response.Write "This Picture's Height is "&Pic_h   
Response.Write "This Picture's Width is "&Pic_w   
Response.End  


3. Img_Reduce 对指定图片缩小或放大并保存(可选择是否加水印,是否加框架)  
必须定义声明 MathPathFrom,MathPathTo  
默认为缩放至150X150 图案 如按比例缩放后图案小于该尺寸,则补充空白图片  
默认文件自动覆盖  
实例: 

复制代码代码如下:


Dim NewObj,NewCommand   
Set NewObj=New AspJpeg   
NewObj.MathPathFrom="f:/test.jpg"   
NewObj.MathPathTo="f:/reduce.jpg"   
NewCommand=NewObj.Img_Reduce   
Set NewObj=Nothing   
If NewCommand<>"" then   
Response.Write "Success"   
Else   
'图片操作过程中出现错误   
Response.Write "Failed"   
End If  


4. Img_WaterMark 给指定图片添加水印  
水印可以为图片 文字 或 2者结合 

标签:

相关文章

热门资讯

玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情 2019-06-22
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
抖音撒撒累累是什么歌 撒撒累累张艺兴歌曲名字
抖音撒撒累累是什么歌 撒撒累累张艺兴歌曲名字 2019-06-05
超A是什么意思 你好a表达的是什么
超A是什么意思 你好a表达的是什么 2019-06-06
返回顶部

499
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40