이미지 자르기() 이미지를 주어진 사각형으로 자르는 데 사용되는 PHP의 내장 함수입니다. 주어진 사각형 영역에서 이미지를 자르고 출력 이미지를 반환합니다. 주어진 이미지는 수정되지 않습니다.
구문
resource imagecrop ($image, $rect)
매개변수
이미지 자르기() 두 개의 매개변수, $image 사용 및 $rect .
-
$이미지 − imagecreatetruecolor()와 같은 이미지 생성 함수에서 반환되는 매개변수입니다. . 이미지의 크기를 생성할 때 사용합니다.
-
$rect − 자르기 사각형은 X, Y, 너비 및 높이 키가 있는 배열입니다.
반환 값
이미지 자르기() 성공 시 잘린 이미지 리소스를 반환하거나 실패 시 false를 반환합니다.
예시
<?php
// It will create an image from the given image
$img = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png');
// This will find the size of the image
$size = min(imagesx($img), imagesy($img));
//This will set the size of the cropped image.
$img2 = imagecrop($img, ['x' => 0, 'y' => 0, 'width' => 500, 'height' => 320]);
if($img2 !== FALSE) {
imagepng($img2, 'C:\xampp\htdocs\pic_cropped.png');
imagedestroy($img2);
}
imagedestroy($img);
?> 출력
imagecrop() 함수 사용 전 이미지 입력

imagecrop() 함수 사용 후 이미지 출력

예시 2
<?php
//load an image from the local drive folder.
$filename = 'C:\xampp\htdocs\Images\img34.png';
$img = imagecreatefrompng($filename );
$ini_x_size = getimagesize($filename)[0];
$ini_y_size = getimagesize($filename )[1];
//the minimum of xlength and ylength to crop.
$crop_measure = min($ini_x_size, $ini_y_size);
// Set the content-type header
//header('Content-Type: image/png');
$crop_array = array('x' =>0 , 'y' => 0, 'width' => $crop_measure, 'height'=>
$crop_measure);
$thumb_img = imagecrop($img, $crop_array);
imagejpeg($thumb_img, 'thumb.png', 100);
?> 출력
