YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

[Function] GetImageSize

페이지 정보

작성자 MintState 댓글 0건 조회 18,484회 작성일 08-11-03 10:31

본문

[Function] GetImageSize

getimagesize
(PHP 3, PHP 4 , PHP 5)

getimagesize -- Get the size of an image
Description
array getimagesize ( string filename [, array imageinfo])

The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag.

If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will return FALSE and generate an error of level E_WARNING.

참고: Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available in PHP 4.3.2. Support for SWC exists as of PHP 4.3.0 and TIFF support was added in PHP 4.2.0

참고: JPEG 2000 support was added in PHP 4.3.2. Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain multiple JPEG 2000 codestreams. In this case, getimagesize() returns the values for the first codestream it encounters in the root of the file.

참고: The getimagesize() function does not require the GD image library.

Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

예 1. getimagesize (file)
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>
 

URL support was added in PHP 4.0.5

예 2. getimagesize (URL)
<?php 
$size = getimagesize("http://www.example.com/gifs/logo.gif");

// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");

?>
 

With JPG images, two extra indexes are returned: channels and bits. channels will be 3 for RGB pictures and 4 for CMYK pictures. bits is the number of bits for each color.

Beginning with PHP 4.3.0, bits and channels are present for other image types, too. However, the presence of these values can be a bit confusing. As an example, GIF always uses 3 channels per pixel, but the number of bits per pixel cannot be calculated for an animated GIF with a global color table.

Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases.

Beginning with PHP 4.3.0, getimagesize() also returns an additional parameter, mime, that corresponds with the MIME type of the image. This information can be used to deliver images with correct HTTP Content-type headers:

예 3. getimagesize() and MIME types
<?php
$size = getimagesize($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
  header("Content-type: {$size['mime']}");
  fpassthru($fp);
  exit;
} else {
  // error
}
?>
 

The optional imageinfo parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed IPTC http://www.iptc.org/ information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable.

예 4. getimagesize() returning IPTC
<?php
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
   $iptc = iptcparse($info["APP13"]);
   var_dump($iptc);
}
?>
 
 
See also image_type_to_mime_type(), exif_imagetype(), exif_read_data() and exif_thumbnail().


GetImageSize() 함수는 배열을 리턴하는데, 각각 width, height, Image Type, string 이다.

$file = "sample.gif"; 
$size = GetImageSize($file); 

index 0 : width 값 
index 1 : height 값 
index 2 : 1~15의 정수 (1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order, 9 = JPC, 10 = JP2, 11 = JPX, 12 
= JB2, 13 = SWC, 14 = IFF) 
index 3 : width=\"300\" height=\"200\" 

echo "$size[0] "; // width 
echo "$size[1] "; // height 
echo "$size[2] "; // byte 
echo "$size[3]"; // byte 



- 이미지 정보를 배열로 나타냅니다.
array getimagesize ( string filename [, array imageinfo])

Array[0] = The width of the image. It is integer data type.
Array[1] = The height of the image. It is an integer data type.
Array[2] = Image Type Flag. It is an integer data type.
Array[3] = String for <img> tag (width="xxx" height="xxx"). It is a string data type.
Array[bits] = Number of channels. It is an integer data type.
Array[channels] = Number of bits. It is an integer data type.
Array[mime] =  MIME type. It is a string data type.

Array[4] = bits (PHP >= 4.3.0)
Array[5] = channels (PHP >= 4.3.0)
Array[6] = mime-type (PHP >= 4.3.0)

<?
$img_type = array(
	1 => 'GIF',
	2 => 'JPG',
	3 => 'PNG',
	4 => 'SWF',
	5 => 'PSD',
	6 => 'BMP',
	7 => 'TIFF(intel byte order)',
	8 => 'TIFF(motorola byte order)',
	9 => 'JPC',
	10 => 'JP2',
	11 => 'JPX',
	12 => 'JB2',
	13 => 'SWC',
	14 => 'IFF',
	15 => 'WBMP',
	16 => 'XBM'
); 
$getimage = getimagesize("images2/alba_application.gif");

echo $img_type[$getimage[2]];

print_r($getimage);
?>

댓글목록

등록된 댓글이 없습니다.

Total 165건 5 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
65 MintState 19504 11-03
64 MintState 26443 11-03
63 MintState 13030 11-03
62 MintState 18901 11-03
61 MintState 20848 11-03
60 MintState 15480 11-03
59 MintState 14582 11-03
58 MintState 12198 11-03
57 MintState 12597 11-03
열람중 MintState 18485 11-03
55 MintState 15302 11-03
54 MintState 16376 11-03
53 MintState 17198 11-03
52 MintState 12668 11-03
51 MintState 12513 11-03
50 MintState 13245 11-03
49 MintState 13359 11-03
48 MintState 14564 11-03
47 MintState 13691 11-03
46 MintState 13725 11-03
45 MintState 14612 10-31
44 MintState 12491 10-31
43 MintState 12790 10-31
42 MintState 15417 10-31
41 MintState 10989 10-31
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™