Python

[howto] Python - 확장자 (없는/표시안된/숨겨진) 이미지의 확장자 알아내기 (※ 파이썬과 PHP 연동)

1315

이미지 확장자 확인 함수

/test.py

 

from io import BytesIO

import requests, imghdr

 

def find_extension(url):

    img = BytesIO(requests.get(url).content)

    return imghdr.what(img)


x = find_extension('http://cfile213.uf.daum.net/image/146BBA474F33FB663B58F4')


print(x)

 


/test.php

 

<?php

$command = escapeshellcmd('python test.py');

$output = shell_exec($command);

$result = iconv('euc-kr', 'UTF-8', $output);

echo $result;

?>

 

결과값: gif

Innisfree 님 (220524) https://sir.kr/pg_tip/17063



분류 제목
basic Python - Home (입문) - 이념 / 추천 링크
basic Python - Intro (소개) - 용도・특징
basic Python - Start (시작) - 파이썬 설치/실행/버전확인
basic Python - Syntax (구문) - 들여쓰기・변수・주석
basic Python - Comment (주석)
basic Python - Variable (변수)
basic Python - DataType (데이터타입) - 자료형
basic Python - Number (숫자)
basic Python - Casting (데이터 타입 변경) - 자료형 변환
basic Python - String (문자열) ★ ※ 색인번호 (= 인덱스) 개념.
basic Python - Boolean (참거짓)
basic Python - Operator (연산자)
basic Python - List (리스트) ★ - 변경 가능한 모음
basic Python - Tuple (투플/튜플) - 변경 불가 모음
basic Python - Set (셋/세트) - '순서(=색인)' 없고, 중복 허용 않는 데이터 모음.
1/32
목록
 홈  PC버전 로그인 일본어
웹디자인언어
서버관리언어
고급코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱 PC버전 로그인