• 회원가입
  • 로그인
  • 구글아이디로 로그인

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

1330  

이미지 확장자 확인 함수

/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 (셋/세트) - '순서(=색인)' 없고, 중복 허용 않는 데이터 모음.
basic Python - Dictionary (딕셔너리) - Key:value 쌍으로 구성된 모음
basic Python - if...elif...else - (이프조건문) ※ 3항연산자 = 삼항연산자
basic Python - While (와일반복문) - 와일문
basic Python - For (포반복문) ★★★★★
basic Python - Function (함수)
1/24
목록
찾아주셔서 감사합니다. Since 2012