이미지(image_lib) Sample

<?php
/**
 * Image Class
 *
 * Created on 2011. 11. 16.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package library
 * @subpackage controllers
 * @version 1.0
 */
class Image_lib_lib extends CI_Controller {
	function __construct() {
		parent::__construct();
	}
	
	function index() {
		$this->load->library('image_lib');
		$data = array();

		// 썸네일 환경 설정
		$config['image_library'] = 'gd2';
		$config['source_image']	= FCPATH . 'sample/images/mypic.jpg';
		$config['thumb_marker'] = '';
		$config['new_image'] = FCPATH . 'sample/images/thumb';
		$config['create_thumb'] = TRUE;
		$config['maintain_ratio'] = TRUE;
		$config['width']	 = 75;
		$config['height']	= 50;
		
		// Library Load시 아래와 같이 지정 가능 함
		// $this->load->library('image_lib', $config);
		
		// 클래스 초기화
		$this->image_lib->clear();
		$this->image_lib->initialize($config);
		
		// 이미지 썸네일 만들기
		if (!$this->image_lib->resize()) {
			$data['thumb_error'] = $this->image_lib->display_errors();
		}

		// 이미지 자르기 환경 설정
		$config['image_library'] = 'gd2';
		$config['source_image']	= FCPATH . 'sample/images/mypic.jpg';
		$config['new_image'] = FCPATH . 'sample/images/crop';
		$config['thumb_marker'] = '';
		$config['x_axis'] = '100';
		$config['y_axis'] = '60';
		
		// 클래스 초기화
		$this->image_lib->clear();
		$this->image_lib->initialize($config); 
		
		// 이미지 자르기
		if (!$this->image_lib->crop()) {
		    $data['crop_error'] =  $this->image_lib->display_errors();
		}

		// 이미지 회전 환경 설정
		$config['image_library'] = 'gd2';
		$config['source_image']	= FCPATH . 'sample/images/mypic.jpg';
		$config['new_image'] = FCPATH . 'sample/images/rotate';
		$config['thumb_marker'] = '';
		$config['rotation_angle'] = 'hor';
				
		// 클래스 초기화
		$this->image_lib->clear();
		$this->image_lib->initialize($config); 
		
		// 이미지 회전
		if (!$this->image_lib->rotate()) {
		    $data['rotate_error'] =  $this->image_lib->display_errors();
		}

		$config['source_image']	= FCPATH . 'sample/images/mypic.jpg';
		$config['new_image'] = FCPATH . 'sample/images/watermark';
		$config['wm_text'] = 'Copyright 2012.04.24 - Youn Lee';
		$config['wm_type'] = 'text';
		$config['wm_font_path'] = BASEPATH . 'fonts/texb.ttf';
		$config['wm_font_size']	= '10';
		$config['wm_font_color'] = 'ffffff';
		$config['wm_vrt_alignment'] = 'bottom';
		$config['wm_hor_alignment'] = 'right';
		$config['wm_padding'] = '-20';

		// 클래스 초기화
		$this->image_lib->clear();
		$this->image_lib->initialize($config); 

		if (!$this->image_lib->watermark()) {
		    $data['watermark_error'] =  $this->image_lib->display_errors();
		}
		
		$this->load->view('image_lib_lib_sample', $data);
	}
}
<?php $this->load->view('inc/header')?>

<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
  <th style="text-align:center" width="20%">구분</th>
  <th width="80%">결과</th>
</tr>
</thead>
<tr>
	<td>이미지 원본</td>
	<td><img src="<?=base_url('sample/images/mypic.jpg')?>" /></td>
</tr>
<tr>
	<td>이미지 썸네일</td>
	<td><img src="<?=base_url('sample/images/thumb/mypic.jpg')?>" /></td>
</tr>
<tr>
	<td>이미지 자르기</td>
	<td><img src="<?=base_url('sample/images/crop/mypic.jpg')?>" /></td>
</tr>
<tr>
	<td>이미지 회전</td>
	<td><img src="<?=base_url('sample/images/rotate/mypic.jpg')?>" /></td>
</tr>
<tr>
	<td>이미지 워터마크 삽입</td>
	<td><img src="<?=base_url('sample/images/watermark/mypic.jpg')?>" /></td>
</tr>
<thead>
<tr>
  <th style="text-align:center" width="20%">구분</th>
  <th width="80%">에러 메시지</th>
</tr>
</thead>
<?php if(isset($thumb_error)):?>
<tr>
	<td>이미지 썸네일 에러 점검</td>
	<td><?=$thumb_error?></td>
</tr>
<?php endif;?>
<?php if(isset($crop_error)):?>
<tr>
	<td>이미지 자르기 에러 점검</td>
	<td><?=$crop_error?></td>
</tr>
<?php endif;?>
<?php if(isset($rotate_error)):?>
<tr>
	<td>이미지 자르기 에러 점검</td>
	<td><?=$rotate_error?></td>
</tr>
<?php endif;?>
<?php if(isset($watermark_error)):?>
<tr>
	<td>이미지 워터마크 에러 점검</td>
	<td><?=$watermark_error?></td>
</tr>
<?php endif;?>
</table>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0069 seconds)