Skip to content
조회 수 14232 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄



getimagesize

Example #1 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
}
?>

Example #2 getimagesize() example

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

Example #3 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");

?>

Example #4 getimagesize() returning IPTC

<?php
$size 
getimagesize("testimg.jpg"$info);
if (isset(
$info["APP13"])) {
    
$iptc iptcparse($info["APP13"]);
    
var_dump($iptc);
}
?>


imagecopyresized

Example #1 Resizing an image

This example will display the image at half size.

<?php
// File and new size
$filename 'test.jpg';
$percent 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width$height) = getimagesize($filename);
$newwidth $width $percent;
$newheight $height $percent;

// Load
$thumb imagecreatetruecolor($newwidth$newheight);
$source imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb$source0000$newwidth$newheight$width$height);

// Output
imagejpeg($thumb);
?>


<?php 
//use this line if you get the error message of using too much memory (strip '//') 
//ini_set ( "memory_limit", "48M"); 

$target_width 800
$target_height 600

if (
ob_get_level() == 0ob_start(); 
if (
$handle opendir('files/')) { 
  while (
false !== ($file readdir($handle))) { 
    if (
$file != "." && $file != "..") { 
      
$destination_path './files/'
      
$target_path $destination_path basename($file); 

      
$extension pathinfo($target_path); 
      
$allowed_ext "jpg, gif, png, bmp, jpeg, JPG"
      
$extension $extension[extension]; 
      
$allowed_paths explode(", "$allowed_ext); 
      
$ok 0
      for(
$i 0$i count($allowed_paths); $i++) { 
        if (
$allowed_paths[$i] == "$extension") { 
          
$ok "1"
        } 
      } 

      if (
$ok == "1") { 

        if(
$extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){ 
          
$tmp_image=imagecreatefromjpeg($target_path); 
        } 

        if(
$extension == "png") { 
          
$tmp_image=imagecreatefrompng($target_path); 
        } 

        if(
$extension == "gif") { 
          
$tmp_image=imagecreatefromgif($target_path); 
        } 

        
$width imagesx($tmp_image); 
        
$height imagesy($tmp_image); 

        
//calculate the image ratio 
        
$imgratio = ($width $height); 

        if (
$imgratio>1) { 
          
$new_width $target_width
          
$new_height = ($target_width $imgratio); 
        } else { 
          
$new_height $target_height
          
$new_width = ($target_height $imgratio); 
        } 

        
$new_image imagecreatetruecolor($new_width,$new_height); 
        
ImageCopyResized($new_image$tmp_image,0,0,0,0$new_width$new_height$width$height); 
        
//Grab new image 
        
imagejpeg($new_image$target_path); 
        
$image_buffer ob_get_contents(); 
        
ImageDestroy($new_image); 
        
ImageDestroy($tmp_image); 
        echo 
" $file resized to $new_width x $new_height <br> \n"
        echo 
str_pad('',4096)."\n";  
        
ob_flush(); 
        
flush(); 
      } 
    } 
  } 
  
closedir($handle); 
  echo 
"Done."
  
ob_end_flush(); 

?>









로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
177 컴퓨터잡담 Windows XP 인증방법 개선으로 업데이트 기능 정상 사용하기 2010.11.03 6569
176 컴퓨터잡담 서비스팩3 설치 후 Client Session manager 문제, SM00905 오류 해결방법 1 2 2010.11.01 14407
175 컴퓨터잡담 북마크 링크 주소모음 2010.10.30 102936
174 컴퓨터잡담 레지스트리 팁 - 로그오프하지 않고 반영하기 2010.10.25 5276
173 컴퓨터잡담 Autohotkey 파일 저장시 한글 깨짐 현상 2010.10.11 11160
172 컴퓨터잡담 javascript만으로 폼전송 2010.10.11 13313
171 컴퓨터잡담 [javascript_tip]자바스크립트 값 넘기기 2 1 2010.10.10 18961
170 컴퓨터잡담 자바스크립트로 전송(submit) 버튼 누르기 3 2010.10.10 103612
169 컴퓨터잡담 [엑셀] SUMPRODUCT 함수 이용, 조건에 따른 중복항목 제외 후 카운트하는 함수 3 2010.10.09 14570
168 컴퓨터잡담 [엑셀] 와일드카드 문자의 변환처리 방법 1 2 2010.10.04 10959
167 컴퓨터잡담 레지스트리 컨트롤로 XP의 가상메모리 페이징 파일의 강제 자동설정을 끌 수 있는 방법 2010.10.02 9074
166 컴퓨터잡담 램디스크 숨기는 방법 2 2010.10.02 5668
165 컴퓨터잡담 autohotkey 변수의 이해 2010.10.02 20555
164 컴퓨터잡담 인터넷익스플로러 로딩속도 빠르게 하는방법 1 2 2010.10.01 12097
163 컴퓨터잡담 -응답없음- 으로 멈춰버린 프로그램 대기시간 줄이는 방법 2010.10.01 7819
162 컴퓨터잡담 스누피 고스트 file 2010.10.01 6027
161 컴퓨터잡담 그림안에 투명텍스트박스 넣기. 2 2010.09.29 9564
160 컴퓨터잡담 PHP Text to Image 1 2010.09.29 13949
159 컴퓨터잡담 오류 socket error #10061 connection 3 2 2010.09.25 53973
158 컴퓨터잡담 엑셀에서 날짜와 시간 계산하는 법 2 2010.09.20 31637
Board Pagination Prev 1 ... 36 37 38 39 40 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소