https://xe1.xpressengine.com/forum/22766671
현재:
$content에서 src 태그를 모두 검색 후 이미지 파일이 있을경우 썸네일 생성시도.
의문: 원본 이미지보다 큰 사이즈의 썸네일 생성이 불가능 하도록하는 조건문이 있음.
이미지 파일 판단 기준: 확장자가 다음중 하나이면 이미지 파일 (jpg, png, jpeg, gif, bmp)
수정:
$content에서 img 태그를 모두 검색 후 썸네일 생성시도.
원본 이미지보다 큰 사이즈의 썸네일 생성을 막는 코드 삭제
이미지 파일 판단 기준: img 태그를 검색 했으므로 무조건 이미지파일로 판단
개선사항:
확장자가 없는 외부 이미지의 썸네일도 생성 가능. 예) 티스토리의 이미지 링크
modules\document\document.item.php
|
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
|
// If not exists, file an image file from the content if(!$source_file) { $content = $this->get('content'); $target_src = null; preg_match_all('/<\s*img[^>]*src\s*=\s*["\']?([^"\']*)/i', $content, $matches, PREG_SET_ORDER); $cnt = count($matches); for($i=0;$i<$cnt;$i++) { $target_src = trim($matches[$i][1]); if(preg_match('/\/(common|modules|widgets|addons|layouts)\//i', $target_src)) continue; else { if(!preg_match('/^(http|https):\/\//i',$target_src)) $target_src = Context::getRequestUri().$target_src; $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111,999999).$this->document_srl)); if(!is_dir('./files/cache/tmp')) FileHandler::makeDir('./files/cache/tmp'); FileHandler::getRemoteFile($target_src, $tmp_file); if(!file_exists($tmp_file)) continue; else { $source_file = $tmp_file; $is_tmp_file = true; break; } } } } |
이 팁을 적용하고 나면
외부 블로그나 그런 곳에서 이미지링크를 문서 본문에 걸어놓아도
그 썸네일이 정상적으로 표시됩니다(기존에는 외부이미지 링크로 썸네일 만들어주지 않았었음...)
댓글 2