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

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

1400  

이미지 확장자 확인 함수

/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



분류 제목
howto Python - 리스트 중복요소 제거. ★ (Remove List Duplicate)
howto Python - 문자열 순서 뒤집기= 역순 ★ (Reverse a String)
howto Python - 사용자 입력값 더하기 ★ (Add Two Numbers)
howto Python - 3과 5의 배수의 합산(합계)
howto Python - digit 숫자 (0~9)를 정사각형 형태로 나열.
howto Python - 유튜브 재생목록 역순으로 List에 담기
howto Python - (홀수/짝수) 여부 판별 (= 홀짝 구분 = even/odd 체크)
howto Python - SyntaxError: Non-ASCII character ~ 인코딩 에러 해결법 (= 파이…
howto Python - 확장자 (없는/표시안된/숨겨진) 이미지의 확장자 알아내기 (※ 파이썬과 PHP 연동)
목록
찾아주셔서 감사합니다. Since 2012