PHP에서 이미지를 자르는 단계는 무엇입니까

藏色散人
풀어 주다: 2023-03-14 08:22:01
원래의
3691명이 탐색했습니다.

PHP를 사용하여 이미지를 자르는 단계: 1. PHP 샘플 파일을 만듭니다. 2. "function imageCropper(){...}" 메서드를 사용하여 이미지 불변 자르기를 달성합니다. 3. "function imageZoom(){.. .} ” 메소드를 사용하면 이미지를 비례적으로 잘라낼 수 있습니다.

PHP에서 이미지를 자르는 단계는 무엇입니까

이 기사의 운영 환경: 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
php
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!