¾È±Ô °øºÎ¹æ

ACTIVE SERVER PAGE > CxImage ÄÄÆ÷³ÍÆ® - À̹ÌÁö »çÀÌÁî Á¶Àý

µî·ÏÀÏ : 2017-07-04 17:15 Á¶È¸¼ö : 53,912

ÄÄÆ÷³ÍÆ®¸¦ ¼³Ä¡ÇÏ¿´À¸¸é, º»°ÝÀûÀÎ ÄÚµù¿¡ µé¾î°¡ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

ÀÌ ÆäÀÌÁö¿¡¼­ Å×½ºÆ®ÇÒ ºÎºÐÀº ½ÇÁ¦ À̹ÌÁö°¡ ¼­¹ö¿¡ ÀÖÀ» °æ¿ì, À̹ÌÁö¸¦ È­¸é¿¡ »Ñ¸±¶§
½ÎÀÌÁ ¿øÇÏ´Â Å©±â·Î Á¶ÀýÇؼ­ »Ñ¸®´Â ¹æ¹ýÀ» ÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

ÀÏ´Ü ÇÊ¿äÇÑ ÆÄÀÏÀ» º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

1. view.asp ( À̹ÌÁö¸¦ »Ñ¸± ÆäÀÌÁö )
2. Thumbnail.asp ( À̹ÌÁö »çÀÌÁ Á¶ÀýÇÏ´Â ÆäÀÌÁö)
3. test.jpg      ( Å×½ºÆ®¿ë À̹ÌÁö ÀÔ´Ï´Ù.)

ÀÌ·¸°Ô ¼¼°³ÀÇ À̹ÌÁö°¡ ÇÊ¿ä ÇÕ´Ï´Ù.

ÀÏ´Ü test.jpg ÀÇ À̹ÌÁö°¡ 500 * 500 ½ÎÀÌÁî¶ó°í °¡Á¤À» ÇßÀ»¶§,

<img src="test.jpg" width=500 height=500>

¿Í °°Àº ű׸¦ ÀÌ¿ëÇؼ­ »Ñ·ÁÁÙ¼ö ÀÖ½À´Ï´Ù. º¸ÅëÀÇ °æ¿ì¿¡´Â¿ä.

»çÀÌÁ Á¶ÀýÇÏ°í ½ÍÀ»°æ¿ì
<img src="test.jpg" width=100 height=100>

¿Í °°ÀÌ »Ñ·Á ÁÙ¼ö ÀÖÀ»°Ì´Ï´Ù.

±×·¯³ª, ¸¸¾à¿¡ À§¿Í °°ÀÌ »Ñ·ÁÁÙ °æ¿ì, ¸¶¿ì½º ¿À¸¥ÂÊ ¹öÆ°À» ´­·¯ À̹ÌÁö¸¦ ´Ù¿îÀ» ¹Þ´Â´Ù¸é,

¾îÂ÷ÇÇ µÎ°æ¿ì ¸ðµÎ 500 * 500 ÀÇ À̹ÌÁö¸¦ ´Ù¿î¹Þ°Ô µË´Ï´Ù.

¿ì¸®°¡ ¿©±â¿¡¼­ ¼¶³×ÀÏÀ» »ç¿ëÇÏ´Â ÀÌÀ¯°¡ ÀÖ½À´Ï´Ù.

¸¸¾à ¿©±â¿¡¼­ 100 * 100 »çÀÌÁî·Î Çؼ­ ´Ù¿îÀ» ¹Þ°Ô ÇÒ·Á¸é, Áï, ¿øº» À̹ÌÁöÀÇ ´Ù¿îÀ» ¸·°í ½Í´Ù¸é
¾î¶»°Ô ÇØ¾ß ÇÒ±î¿ä?????

ÀÌ·± °æ¿ì¿¡ ¼¶³×ÀÏ ÄÄÆ÷³ÍÆ®¸¦ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù.

±×·³, ¿©±â¿¡¼­ Thumbnail.asp ÀÇ ¼Ò½º¸¦ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
 
<%
	'-----------------------------------------
	'	ÆÄÀϸí Thumbnail.asp
	'-----------------------------------------
	Response.ContentType = "image/jpeg"

	Width = Int(Request("Width"))
	Height = Int(Request("Height"))
	
	VFilePath = Request("filepath")
	FilePath = Server.MapPath(VFilePath)

	Quality=100
	
  	Set objCxImage = Server.CreateObject("CxImageATL.CxImage")
  	Call objCxImage.Load(FilePath,GetFileType(FilePath))
  
  	widthOrig = CDbl(objCxImage.GetWidth())
  	heightOrig = CDbl(objCxImage.GetHeight())
  
  	fx = widthOrig/Width
  	fy = heightOrig/Height 

  	If fx>fy Then 
  		f=fx 
  	Else 
  		f=fy  
  	end if
  		
	If f<1 Then 
		f=1
	 	widthTh = Int(widthOrig/f)
	 	heightTh = Int(heightOrig/f)
  	Else
	 	widthTh = Width
	 	heightTh = Height
  	End If
  	
  	Call objCxImage.Resample(widthTh,heightTh,2)
  	BinData = objCxImage.ImageForASP(2,Quality)

	Response.BinaryWrite BinData

	Function GetFileType(sFile)
  		dot = InStrRev(sFile, ".")
  		filetype=2
  		If dot > 0 Then 
  			sExt = LCase(Mid(sFile, dot + 1, 3))
  		end if
  			
  		If sExt = "bmp" Then filetype = 0
  		If sExt = "gif" Then filetype = 1
  		If sExt = "jpg" Then filetype = 2
  		If sExt = "png" Then filetype = 3
  		If sExt = "ico" Then filetype = 4
  		If sExt = "tif" Then filetype = 5
  		If sExt = "tga" Then filetype = 6
  		If sExt = "pcx" Then filetype = 7
  		
  		GetFileType=filetype
	End Function

	%>



Thumbnail.asp ÆÄÀÏÀÇ Àüü ¼Ò½º ÀÔ´Ï´Ù.

À§ÀÇ ¼Ò½º¸¦ °£¶ôÇÏ°Ô ¼³¸íÀ» µå¸®¸é,
Response.ContentType = "image/jpeg"
ÆÄÀÏÀÇ Å¸ÀÔÀ» À̹ÌÁöÇüÀ¸·Î ¹Ù²ß´Ï´Ù.
½ÇÁ¦ asp ÆÄÀÏÀÌÁö¸¸, À§ÀÇ ¼³Á¤À¸·Î ¼­¹ö´Â À̹ÌÁö·Î ÀνÄÀ» ÇÏ°Ô µË´Ï´Ù.

Width = Int(Request("Width"))
Height = Int(Request("Height"))
VFilePath = Request("filepath")
FilePath = Server.MapPath(VFilePath)
Quality=100


À§ÀÇ ¼Ò½º´Â ¹Ù²Ü À̹ÌÁöÀÇ »çÀÌÁî(width,height) °ªÀ» ¹Þ°í, filepath ¸¦ ¹Þ°Ô µË´Ï´Ù.
Server.MapPath(VFilePath) ¸Þ¼Òµå¸¦ ÅëÇØ ½ÇÁ¦ ¼­¹öÀÇ °æ·Î¸¦ (¿¹: c:\wwwroot\....) ÇüÅ·Î
¹Ù²Ù¾î ÁÖ°ÚÁö¿ä?
Quality º¯¼ö´Â º¯È¯ÈÄ À̹ÌÁöÀÇ Ä÷¸®Æ¼¸¦ ³ªÅ¸³À´Ï´Ù.

Set objCxImage = Server.CreateObject("CxImageATL.CxImage")
Call objCxImage.Load(FilePath,GetFileType(FilePath))


  À§ÀÇ ¼Ò½º´Â CxImage ÀνºÅÏÆ®¸¦ ¸¸µé¾î ÁÝ´Ï´Ù.
  ±×¸®°í, FilePath ÀÇ À̹ÌÁö¸¦ ¼­¹ö¿¡¼­ Àоî¿Í ±â¾ïÀåÄ¡¿¡ Load ¸¦ ÇÏ´Â ¼Ò½º ÀÔ´Ï´Ù.
 
  GetFileType(FilePath) À̺κÐÀº ¾Æ·¡ºÎºÐ¿¡ Function GetFileType() ÇÔ¼ö¸¦ ÅëÇØ Äڵ尪À¸·Î
  ¹Ù²î°Ô µË´Ï´Ù. bmp ÆÄÀÏÀÏ °æ¿ì 0 , gifÆÄÀÏÀÇ °æ¿ì 1 ,,,, µîÀ¸·Î ¹Ù²î°Ô µË´Ï´Ù.
 
widthOrig = CDbl(objCxImage.GetWidth())
heightOrig = CDbl(objCxImage.GetHeight())


  À§ÀÇ ¼Ò½º´Â GetWidth() , GetHeight() ¸Þ¼Òµå¸¦ ÅëÇØ ¿øº»À̹ÌÁöÀÇ ½ÇÁ¦ »çÀÌÁ ±¸ÇÕ´Ï´Ù.
 
  ±×¸®°í, ƯÁ¤·ÎÁ÷À» ÅëÇØ widthTh , heightTh °ªÀ» ±¸ÇÏ°Ô µË´Ï´Ù.
 
  width=100 , height=100 À̶õ °ªÀ» ¹Þ¾ÒÀ»¶§, ÀÌ°ªÀ» °ð¹Ù·Î ÁöÁ¤ÇÑ´Ù¸é, À̹ÌÁö°¡ ¿øº» À̹ÌÁö¿Í
  »ó°ü¾øÀÌ ¹«Á¶°Ç 100 * 100 ½ÎÀÌÁî·Î ¹Ù²î±â ¶§¹®¿¡ À̹ÌÁö°¡ ±ú¾îÁú¼ö ÀÖ½À´Ï´Ù.
 
  À§ÀÇ ·ÎÁ÷À» ÅëÇØ width , height °ªÀ» ºñÀ²ÀûÀ¸·Î ÁÙ¿©ÁÙ¼ö ÀÖ½À´Ï´Ù.
 
Call objCxImage.Resample(widthTh,heightTh,2)
BinData = objCxImage.ImageForASP(2,Quality) 


  À§ÀÇ ¼Ò½º´Â ReSample ¸Þ¼Òµå¸¦ ÀÌ¿ëÇؼ­ À̹ÌÁöÀÇ »çÀÌÁ ¸Þ¸ð¸®»ó¿¡¼­ ÁÙ¿©ÁÖ°Ô µË´Ï´Ù.
  ImageForASP ¸Þ¼Òµå´Â ¸Þ¸ð¸®¿¡ ÀÖ´Â À̹ÌÁö µ¥ÀÌŸ °ªÀ» BinData º¯¼ö¿¡ ³Ö¾îÁÝ´Ï´Ù.

  Response.BinaryWrite BinData

  ³¡À¸·Î Response °´Ã¼ÀÇ BinaryWrite ÇÁ·ÎÆÛƼ¸¦ ÀÌ¿ëÇؼ­ BinData ¸¦ Ãâ·ÂÇØ ÁÝ´Ï´Ù.
 
  ÇöÀç ContentType À» image/jpeg ÇüÀ¸·Î óÀ½¿¡ ¼³Á¤Ç߱⠶§¹®¿¡ °ªÀ» »Ñ¸®¸é, ¸Þ¸ð¸®¿¡ ÀÖ´Â
  À̹ÌÁö µ¥ÀÌÅÍÀÇ °ªÀÌ Å¬¶óÀ̾ðÆ®¿¡°Ô »Ñ·ÁÁÖ°Ô µË´Ï´Ù.
 
'-------------------------------
' ÆÄÀϸí : View.asp
'-------------------------------
<img src="Thumbnail.asp?filepath=/test.jpg&width=100&height=100">

 
  À§ÀÇ ¼Ò½º´Â View.asp ÆÄÀÏÀÇ ¼Ò½º ÀÔ´Ï´Ù.
 
  <img ... > ű׸¦ ÀÌ¿ëÇؼ­ À̹ÌÁö¸¦ »Ñ¸³´Ï´Ù. ±×·¯³ª, À̹ÌÁö¸íÀ» ¾²´Â°Ô ¾Æ´Ï¶ó,
  Áö±Ý²¯ ÀÛ¼ºÇÑ Thumbnail.asp ÆÄÀÏÀ» »Ñ·ÁÁÝ´Ï´Ù. ³Ñ°ÜÁÖ´Â °ªÀ» filepath , width , height
  °ªÀ» º¸³»¸é È­¸é¿¡´Â ½ÇÁ¦·Î Àû¿ëµÈ 100 * 100 ÀÇ À̹ÌÁö°¡ »Ñ·ÁÁý´Ï´Ù.
 
  ¸¶¿ì½º ¿À¸¥ÂÊ ¹öÆ°À» ´­·¯ À̹ÌÁö¸¦ ´Ù¿î ¹Þ¾Æ º¸½Ê½Ã¿À.
  ½ÇÁ¦·Î ´Ù¿îµÇ´Â À̹ÌÁö´Â 100 * 100 À̹ÌÁö¸¦ ´Ù¿î ¹Þ¾ÆÁö´Â °ÍÀ» È®ÀÎÇϽǼö ÀÖÀ»°Ì´Ï´Ù.
 
  Áñ°Å¿î ½Ã°£ µÇ½Ê½Ã¿À...   
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.