테스트 사이트 - 개발 중인 베타 버전입니다

function get_view_thumbnail($contents, $thumb_width=0) alt속성 사용법좀 알려주세요 채택완료

그누보드좋아요 10년 전 조회 5,370

</p><p>function get_view_thumbnail($contents, $thumb_width=0)</p><p>{</p><p>    global $board, $config;</p><p> </p><p>    if (!$thumb_width)</p><p>        $thumb_width = $board['bo_image_width'];</p><p> </p><p>    // $contents 중 img 태그 추출</p><p>    $matches = get_editor_image($contents, true);</p><p> </p><p>    if(empty($matches))</p><p>        return $contents;</p><p> </p><p>    for($i=0; $i<count($matches[1]); $i++) {</p><p> </p><p>        $img = $matches[1][$i];</p><p>        preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);</p><p>        $src = $m[1];</p><p>        preg_match("/style=[\"\']?([^\"\'>]+)/i", $img, $m);</p><p>        $style = $m[1];</p><p>        preg_match("/width:\s*(\d+)px/", $style, $m);</p><p>        $width = $m[1];</p><p>        preg_match("/height:\s*(\d+)px/", $style, $m);</p><p>        $height = $m[1];</p><p>        preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img, $m);</p><p>        $alt = get_text($m[1]);</p><p> </p><p>        // 이미지 path 구함</p><p>        $p = parse_url($src);</p><p>        if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)</p><p>            $data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);</p><p>        else</p><p>            $data_path = $p['path'];</p><p> </p><p>        $srcfile = G5_PATH.$data_path;</p><p> </p><p>        if(is_file($srcfile)) {</p><p>            $size = @getimagesize($srcfile);</p><p>            if(empty($size))</p><p>                continue;</p><p> </p><p>            // jpg 이면 exif 체크</p><p>            if($size[2] == 2 && function_exists('exif_read_data')) {</p><p>                $degree = 0;</p><p>                $exif = @exif_read_data($srcfile);</p><p>                if(!empty($exif['Orientation'])) {</p><p>                    switch($exif['Orientation']) {</p><p>                        case 8:</p><p>                            $degree = 90;</p><p>                            break;</p><p>                        case 3:</p><p>                            $degree = 180;</p><p>                            break;</p><p>                        case 6:</p><p>                            $degree = -90;</p><p>                            break;</p><p>                    }</p><p> </p><p>                    // 세로사진의 경우 가로, 세로 값 바꿈</p><p>                    if($degree == 90 || $degree == -90) {</p><p>                        $tmp = $size;</p><p>                        $size[0] = $tmp[1];</p><p>                        $size[1] = $tmp[0];</p><p>                    }</p><p>                }</p><p>            }</p><p> </p><p>            // 원본 width가 thumb_width보다 작다면</p><p>            if($size[0] <= $thumb_width)</p><p>                continue;</p><p> </p><p>            // Animated GIF 체크</p><p>            $is_animated = false;</p><p>            if($size[2] == 1) {</p><p>                $is_animated = is_animated_gif($srcfile);</p><p>            }</p><p> </p><p>            // 썸네일 높이</p><p>            $thumb_height = round(($thumb_width * $size[1]) / $size[0]);</p><p>            $filename = basename($srcfile);</p><p>            $filepath = dirname($srcfile);</p><p> </p><p>            // 썸네일 생성</p><p>            if(!$is_animated)</p><p>                $thumb_file = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, false);</p><p>            else</p><p>                $thumb_file = $filename;</p><p> </p><p>            if(!$thumb_file)</p><p>                continue;</p><p> </p><p>            if ($width) {</p><p>                $thumb_tag = '<img src="'.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"/>';</p><p>            } else {</p><p>                $thumb_tag = '<img src="'.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'"/>';</p><p>            }</p><p> </p><p>            // $img_tag에 editor 경로가 있으면 원본보기 링크 추가</p><p>            $img_tag = $matches[0][$i];</p><p>            if(strpos($img_tag, G5_DATA_DIR.'/'.G5_EDITOR_DIR) && preg_match("/\.({$config['cf_image_extension']})$/i", $filename)) {</p><p>                $imgurl = str_replace(G5_URL, "", $src);</p><p>                $thumb_tag = '<a href="'.G5_BBS_URL.'/view_image.php?fn='.urlencode($imgurl).'" target="_blank" class="view_image">'.$thumb_tag.'</a>';</p><p>            }</p><p> </p><p>            $contents = str_replace($img_tag, $thumb_tag, $contents);</p><p>        }</p><p>    }</p><p> </p><p>    return $contents;</p><p>}</p><p>

함수는 이함수를 사요 하구요.

 

</p><p><?php</p><p>            // 파일 출력(이미지)</p><p>            $v_img_count = count($view['file']);</p><p>            if($v_img_count) {</p><p>                echo "<div id=\"bo_v_img\">\n";</p><p>                         $vthumb = get_view_thumbnail($view['file']['0']['view']);</p><p>                         echo $vthumb;</p><p>                echo "</div>\n";</p><p>             }</p><p> </p><p>             ?> </p><p><span style="font-size: 13.3333330154419px; line-height: 1.5;">

 

여기서 이미지를 출력 하는 부분입니다. 어디에서 추가를 시켜야 이미지에 alt속성이 붙을까요.​

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
10년 전

    if ($width) {

093                $thumb_tag = '.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"/>';
094            } else {
095                $thumb_tag = '.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'"/>';
096            }

 

92번째 줄에 $alt 변수있습니다. 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인