PIL을 사용하여 종횡비 보존으로 이미지 크기 조정
썸네일을 생성하거나 이미지 크기를 조정할 때 이미지 충실도를 유지하려면 종횡비를 유지하는 것이 중요합니다. PIL은 너비와 높이 크기를 동적으로 조정하면서 이를 달성할 수 있는 간단한 방법을 제공합니다.
가로세로 비율을 유지하면서 PIL을 사용하여 이미지 크기를 조정하려면 다음 단계를 따르세요.
- 최대 크기 정의: 너비와 크기 측면에서 크기가 조정된 이미지에 대해 원하는 최대 크기를 결정합니다. height.
- 크기 조정 비율 계산: 최대 너비를 원본 이미지 너비로 나눈 값과 최대 높이를 원본 이미지 높이로 나눈 값 사이의 최소값을 취하여 크기 조정 비율을 계산합니다. 이 비율을 사용하면 이미지 크기가 비례적으로 조정됩니다.
- 새 크기 계산: 원본 이미지 크기에 크기 조정 비율을 곱하여 새 이미지 크기를 계산합니다.
편의를 위해 PIL은 이미지의 종횡비를 유지하면서 이미지 크기를 조정하기 위해 특별히 설계된 방법인 Image.thumbnail을 제공합니다. 다음은 Image.thumbnail을 사용하여 썸네일을 생성하는 방법을 보여주는 PIL 문서의 예입니다.
import os, sys import Image size = 128, 128 for infile in sys.argv[1:]: outfile = os.path.splitext(infile)[0] + ".thumbnail" if infile != outfile: try: im = Image.open(infile) im.thumbnail(size, Image.Resampling.LANCZOS) im.save(outfile, "JPEG") except IOError: print "cannot create thumbnail for '%s'" % infile
이 예는 Image.thumbnail을 사용하여 입력 이미지 목록에서 썸네일을 생성하고 해당 측면을 유지하는 방법을 보여줍니다. 최종 크기가 지정된 치수 내에 있는지 확인하면서 비율을 조정하세요.
위 내용은 종횡비를 유지하면서 이미지 크기를 조정하는 데 PIL을 어떻게 사용할 수 있습니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.