자동 다운로더 개발하다 까먹으면 안될 것 같아 옮겨봅니다.

<?php
$source = '/home/user/zip/compressed.zip';
$storage = '/home/user/thumbnails/';
$workspace = '/tmp/thumbnailmaker/';
$path = $storage.'/resized.jpg';

@mkdir($storage, 0777);
@mkdir($workspace, 0777, true);
@unlink($path);

$zip = new ZipArchive();
if($zip->open($source) === true) {
	for($i = 0, $cnt = $zip->numFiles; $i < $cnt; $i++) {
		$fname = $zip->getNameIndex($i);
		if(preg_match('/(jpe?g|gif|png)/', pathinfo($fname, PATHINFO_EXTENSION))) {
			$tpath = $workspace.'/'.sha1(time().rand(0,99));
			copy('zip://'.$source.'#'.$fname, $tpath);

			list($wo, $ho, $ftype) = getimagesize($tpath);
			switch($ftype) {
				case 1: $original = imagecreatefromgif($tpath); break;
				case 2: $original = imagecreatefromjpeg($tpath); break;
				case 3: $original = imagecreatefrompng($tpath); break;
				case 15: $original = imagecreatefromwbmp($tpath); break;
				default: echo 'Can\'t make a thumbnail: '.$ftype; unlink($tpath); break(2);
			}
			unlink($tpath);

			$w = 80; $h = 60;
			$resized = imagecreatetruecolor($w, $h);
			imagecopyresampled($resized, $original, 0, 0, 0, 0, $w, $h, $wo, $ho);
			imagepng($resized, $path, 9);

			chmod($path, 0644);
			break;
		}
	}
}
?>
getimagesize()이 반환하는 image type 정보
print_r(get_defined_constants());

위 함수를 호출함으로써 알 수 있습니다. PHP 5.3에서는 다음과 같은 값들을 반환합니다.

[IMAGETYPE_GIF] => 1
[IMAGETYPE_JPEG] => 2
[IMAGETYPE_PNG] => 3
[IMAGETYPE_SWF] => 4
[IMAGETYPE_PSD] => 5
[IMAGETYPE_BMP] => 6
[IMAGETYPE_TIFF_II] => 7
[IMAGETYPE_TIFF_MM] => 8
[IMAGETYPE_JPC] => 9
[IMAGETYPE_JP2] => 10
[IMAGETYPE_JPX] => 11
[IMAGETYPE_JB2] => 12
[IMAGETYPE_SWC] => 13
[IMAGETYPE_IFF] => 14
[IMAGETYPE_WBMP] => 15
[IMAGETYPE_JPEG2000] => 9
[IMAGETYPE_XBM] => 16
[IMAGETYPE_ICO] => 17
[IMAGETYPE_UNKNOWN] => 0
[IMAGETYPE_COUNT] => 18

[PHP] bmp 이미지 읽는 imagecreatefrombmp 함수

저작자 표시 비영리
신고
  1. 블캣느님
    쩌러쩌러~~!~!~!~!~!~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Name __

Password __

Link (Your Website)

Comment