Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

섬네일 이미지 처리 방식 개선 요청 #1417

Closed
socialskyo opened this issue Apr 16, 2015 · 5 comments
Closed

섬네일 이미지 처리 방식 개선 요청 #1417

socialskyo opened this issue Apr 16, 2015 · 5 comments

Comments

@socialskyo
Copy link

socialskyo commented Apr 16, 2015

https://www.xpressengine.com/forum/22766671

현재:
$content에서 src 태그를 모두 검색 후 이미지 파일이 있을경우 썸네일 생성시도.
의문: 원본 이미지보다 큰 사이즈의 썸네일 생성이 불가능 하도록하는 조건문이 있음.
이미지 파일 판단 기준: 확장자가 다음중 하나이면 이미지 파일 (jpg, png, jpeg, gif, bmp)

수정:
$content에서 img 태그를 모두 검색 후 썸네일 생성시도.
원본 이미지보다 큰 사이즈의 썸네일 생성을 막는 코드 삭제
이미지 파일 판단 기준: img 태그를 검색 했으므로 무조건 이미지파일로 판단

개선사항:
확장자가 없는 외부 이미지의 썸네일도 생성 가능. 예) 티스토리의 이미지 링크

modules\document\document.item.php

// 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;
                    }
                }
            }
        }

외부 이미지 호스팅 서비스를 통해서 긁어오는 짤방 이 많은 요즈음 이렇게 되면 더 좋을 듯 하여
대신해서 올려 봅니다.

@fromthere
Copy link

섬네일 사이즈가 이미지보다 큰 시점에서 섬네일의 의미가 있는지 의문입니다.
섬네일 자체가 큰 이미지를 축소해 둬서 미리보기시 전송되는 데이터의 양을 줄이는 것인데, 섬네일이 더 크다면 섬네일을 쓰는 의미가 없지 않을까요?

@kijin
Copy link
Contributor

kijin commented Apr 16, 2015

섬네일 사이즈가 이미지보다 큰 시점에서 섬네일의 의미가 있는지 의문입니다.

섬네일은 용량을 줄이는 목적도 있지만, 모든 이미지를 일정한 크기로 통일하여 디자인의 일관성을 유지하는 목적도 있습니다. 예를 들어 요즘 사진 위주의 커뮤니티들은 섬네일을 큼지막하게 (예: 400x300) 생성하는 경우도 꽤 많습니다. 그런데 이렇게 큰 섬네일을 생성하도록 설정해 둔 게시판에 작은 그림을 올린다면 디자인이 삐뚤어지는 문제가 생길 수 있죠.

또한 원본이미지가 bmp, png 등의 포맷으로 되어 있다면 (윈도우에서 스샷 찍고 그림판으로 저장하면 대개 이런 포맷으로 저장됩니다) 같은 크기의 jpg로 변환하기만 해도 용량이 상당히 많이 절약됩니다. 움짤 gif도 마찬가지... 움직이지 않는 jpg로 변환하면 크기를 몇 배로 키우더라도 용량은 오히려 작아지죠.

@bjrambo
Copy link
Contributor

bjrambo commented Apr 16, 2015

http://www.swhite523.com/data 대표적으로 섬네일이 생성되지 않으면 안되는 게시판의 형태는 이렇습니다.

@cococob
Copy link

cococob commented Oct 4, 2015

아니 외부이미지 복사해서 오면 섬네일생성이 안되는 경우 이 팁은 정말 유용한데
아직도 반영안될 이유가 있나요..? 매번 코어 업뎃때마다 수정해서 넣는데
문제가 있어서 반영이 안되는건지.....뭔지.....

@ghost ghost self-assigned this May 11, 2016
@ghost ghost added the type/enhancement label May 11, 2016
@ghost ghost added this to the 1.8.20 milestone May 11, 2016
@kijin
Copy link
Contributor

kijin commented May 12, 2016

추가 - $target_src를 추출한 후 htmlspecialchars_decode()로 처리해 줘야 합니다. 외부이미지 주소에 &가 포함되어 있는 경우 HTML 소스에서는 &amp;로 표시되기 때문입니다. 현재 상태에서는 주소에 &가 포함되어 있는 대부분의 외부 링크를 &amp;로 잘못 요청하고 있습니다.

ghost pushed a commit that referenced this issue May 12, 2016
- AS-IS 이미지의 URL이 'jpg' 등의 확장자로 끝나는 파일만 썸네일 생성 대상으로 함
- TO-BE 이미지 URL의 확장자 검색을 제외하고 `<img>`태그의 'src'로 지정된 URL은 썸네일 생성 대상으로 함

- 확장자가 없거나, parameter가 붙는 이미지 주소가 대상이 될 수 있도록 변경
- 임시 파일이 정상적으로 제거되지 않을 수 있는 문제를 수정
- 임시 파일의 이름을 정하는 방법 변경
@ghost ghost closed this as completed May 13, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants