PHP를 사용하여 이미지를 자르는 단계: 1. PHP 샘플 파일을 만듭니다. 2. "function imageCropper(){...}" 메서드를 사용하여 이미지 불변 자르기를 달성합니다. 3. "function imageZoom(){.. .} ” 메소드를 사용하면 이미지를 비례적으로 잘라낼 수 있습니다.
이 기사의 운영 환경: Windows 7 시스템, PHP 버전 7.4, DELL G3 컴퓨터
PHP로 사진을 자르는 단계는 무엇입니까?
PHP를 사용하여 이미지 불변 자르기 및 이미지 비례 자르기를 구현하는 방법
이 문서에서는 PHP에서 이미지 불변 자르기 및 이미지 비례 자르기를 구현하는 예를 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다.
그림 변경되지 않은 자르기
$target_ratio){ // image-to-height $cropped_width = $source_width; $cropped_height = $source_width * $target_ratio; $source_x = 0; $source_y = ($source_height - $cropped_height) / 2; }elseif ($source_ratio < $target_ratio){ //image-to-widht $cropped_width = $source_height / $target_ratio; $cropped_height = $source_height; $source_x = ($source_width - $cropped_width) / 2; $source_y = 0; }else{ //image-size-ok $cropped_width = $source_width; $cropped_height = $source_height; $source_x = 0; $source_y = 0; } switch ($source_mime){ case 'image/gif': $source_image = imagecreatefromgif($source_path); break; case 'image/jpeg': $source_image = imagecreatefromjpeg($source_path); break; case 'image/png': $source_image = imagecreatefrompng($source_path); break; default: return ; break; } $target_image = imagecreatetruecolor($target_width, $target_height); $cropped_image = imagecreatetruecolor($cropped_width, $cropped_height); // copy imagecopy($cropped_image, $source_image, 0, 0, $source_x, $source_y, $cropped_width, $cropped_height); // zoom imagecopyresampled($target_image, $cropped_image, 0, 0, 0, 0, $target_width, $target_height, $cropped_width, $cropped_height); header('Content-Type: image/jpeg'); imagejpeg($target_image); imagedestroy($source_image); imagedestroy($target_image); imagedestroy($cropped_image); } $filename = "8fcb7a0831b79c61.jpg"; imageCropper($filename,200,200); ?>
그림 비례 자르기
추천 학습: "PHP 비디오 튜토리얼"
위 내용은 PHP에서 이미지를 자르는 단계는 무엇입니까의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!