이미지 조작 클래스 업그레이드

문서

변경된 사항

  • CI3에서 생성자 또는 initialize() 메서드에 전달되던 설정이 CI4의 새 메서드에서 지정하는 방식으로 변경되었습니다.

  • create_thumb과 같은 일부 설정이 제거되었습니다.

  • CI4에서는 조작된 이미지를 저장하기 위해 save() 메서드를 호출해야 합니다.

  • display_errors()가 제거되었으며, 오류 발생 시 예외가 던져집니다.

업그레이드 가이드

  1. 클래스 내에서 $this->load->library('image_lib');$image = \Config\Services::image();로 변경하십시오.

  2. 생성자 또는 initialize() 메서드에 전달되던 설정을 해당 메서드에서 지정하는 방식으로 변경하십시오.

  3. 파일을 저장하려면 save() 메서드를 호출하십시오.

코드 예제

CodeIgniter 버전 3.x

<?php

$config['image_library']  = 'gd2';
$config['source_image']   = '/path/to/image/mypic.jpg';
$config['create_thumb']   = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']          = 75;
$config['height']         = 50;

$this->load->library('image_lib', $config);

$this->image_lib->resize();

CodeIgniter 버전 4.x

<?php

$image = \Config\Services::image();

$image
    ->withFile('/path/to/image/mypic.jpg')
    ->resize(75, 50, true)
    ->save('/path/to/image/mypic_thumb.jpg');