PHP实现图片不变型裁剪及图片按比例裁剪的方法,
本文实例讲述了PHP实现图片不变型裁剪及图片按比例裁剪的方法。分享给大家供大家参考,具体如下:
图片不变型裁剪
<?php /** * imageCropper * @param string $source_path * @param string $target_width * @param string $target_height */ function imageCropper($source_path, $target_width, $target_height){ $source_info = getimagesize($source_path); $source_width = $source_info[0]; $source_height = $source_info[1]; $source_mime = $source_info['mime']; $source_ratio = $source_height / $source_width; $target_ratio = $target_height / $target_width; if ($source_ratio > $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 /** * imageZoom * @param string $file * @param double $zoom */ function imageZoom($filename,$zoom=0.6){ //baseinfo $sourceImageInfo = getimagesize($filename); $sourceWidth = $sourceImageInfo[0]; $sourceHeight = $sourceImageInfo[1]; $sourceMine = $sourceImageInfo['mime']; $sourceRatio = $sourceWidth/$sourceHeight; $sourceX = 0; $sourceY = 0; //zoom $targetRatio = $zoom; //target-widht-height $targetWidth = $sourceWidth*$targetRatio; $targetHeight = $sourceHeight*$targetRatio; //init-params $sourceImage = null; switch($sourceMine){ case 'image/gif': $sourceImage = imagecreatefromgif($filename); break; case 'image/jpeg': $sourceImage = imagecreatefromjpeg($filename); break; case 'image/png': $sourceImage = imagecreatefrompng($filename); break; default: return ; break; } //temp-target-image $tempSourceImage = imagecreatetruecolor($sourceWidth, $sourceHeight); $targetImage = imagecreatetruecolor($targetWidth,$targetHeight); //copy imagecopy($tempSourceImage, $sourceImage, 0, 0, $sourceX, $sourceY, $sourceWidth, $sourceHeight); //zoom imagecopyresampled($targetImage, $tempSourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $sourceWidth, $sourceHeight); //header header('Content-Type: image/jpeg'); //image-loading imagejpeg($targetImage); //destroy imagedestroy($tempSourceImage); imagedestroy($sourceImage); imagedestroy($targetImage); } $filename = "8fcb7a0831b79c61.jpg"; imageZoom($filename); ?>
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- php结合imgareaselect实现图片裁剪
- MacOS 安装 PHP的图片裁剪扩展Tclip
- PHP图片处理之使用imagecopyresampled函数裁剪图片例子
- PHP实现图片裁剪、添加水印效果代码
- PHP图片裁剪函数(保持图像不变形)
- php使用imagick模块实现图片缩放、裁剪、压缩示例
- PHP加Nginx实现动态裁剪图片方案
- 使用gd库实现php服务端图片裁剪和生成缩略图功能分享
- php+js实现图片的上传、裁剪、预览、提交示例
- php图片的裁剪与缩放生成符合需求的缩略图
- PHP 裁剪图片成固定大小代码方法

로드 밸런싱은 세션 관리에 영향을 미치지 만 세션 복제, 세션 끈적임 및 중앙 집중식 세션 스토리지로 해결할 수 있습니다. 1. 세션 복제 복사 서버 간의 세션 데이터. 2. 세션 끈은 사용자 요청을 동일한 서버로 안내합니다. 3. 중앙 집중식 세션 스토리지는 Redis와 같은 독립 서버를 사용하여 세션 데이터를 저장하여 데이터 공유를 보장합니다.

SessionLockingIsateChniqueSureDureauser의 SessionLockingSsessionRemainSexclusivetoOneuseratatime.itiscrucialforpreptingdatacorruptionandsecurityBreachesInmulti-userApplications.sessionLockingSogingSompletEdusingserVerver-sidelockingMegynisms, unrasprantlockinj

PHP 세션의 대안에는 쿠키, 토큰 기반 인증, 데이터베이스 기반 세션 및 Redis/Memcached가 포함됩니다. 1. Cookies는 클라이언트에 데이터를 저장하여 세션을 관리합니다. 이는 단순하지만 보안이 적습니다. 2. Token 기반 인증은 토큰을 사용하여 사용자를 확인합니다. 이는 매우 안전하지만 추가 논리가 필요합니다. 3. Database 기반 세션은 데이터베이스에 데이터를 저장하여 확장 성이 좋지만 성능에 영향을 줄 수 있습니다. 4. Redis/Memcached는 분산 캐시를 사용하여 성능 및 확장 성을 향상하지만 추가 일치가 필요합니다.

SessionHijacking은 사용자의 SessionID를 얻음으로써 사용자를 가장하는 공격자를 말합니다. 예방 방법은 다음과 같습니다. 1) HTTPS를 사용한 의사 소통 암호화; 2) SessionID의 출처를 확인; 3) 보안 세션 생성 알고리즘 사용; 4) 정기적으로 SessionID를 업데이트합니다.

이 기사는 PHP에 대해 설명하고, 전체 형식, 웹 개발의 주요 용도, Python 및 Java와의 비교 및 초보자를위한 학습 용이성을 자세히 설명합니다.

PHP는 유효성 검사, 소독 및 보안 데이터베이스 상호 작용을 통해 보안을 보장하면서 $ \ _ post 및 $ \ _를 사용하여 데이터 양식 데이터를 처리합니다.

이 기사는 PHP와 ASP.NET을 비교하여 대규모 웹 응용 프로그램, 성능 차이 및 보안 기능에 대한 적합성에 중점을 둡니다. 둘 다 대규모 프로젝트에서는 실용적이지만 PHP는 오픈 소스 및 플랫폼 독립적이며 ASP.NET,

PHP의 사례 감도는 다양합니다. 함수는 무감각하고 변수와 클래스는 민감합니다. 모범 사례에는 일관된 이름 지정 및 비교를위한 사례 감수 기능 사용이 포함됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
