갤러리 에서 사진 Exif 데이타 출력 방법은 없을까요

아래 워드프레스 EXIF 플러그인을 이용한 방법이 아직 구현되지 않는다고 답변 주셔서 너무감사합니다.

그러면 코스모스팜 갤러리에서 사진을 올렸을 경우 사진 data를 자동으로 나오게 할 다른 방법은 없을까요?

혹시 판매하시는 갤러리 중에라도 없을까요?

사진 사이트라서 정보 나오는게 정말 중요하거든요

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  • 예제를 만들어 봤습니다.

    게시글 본문에 이미지가 있다면, 이미지 정보를 하단에 보여줄 수 있습니다.

     

    우선 테마의 functions.php 파일 하단에 아래 코드를 추가해주세요.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    if(!function_exists('my_kboard_exif_read_data')){
        add_action('wp_ajax_my_kboard_exif_read_data', 'my_kboard_exif_read_data');
        add_action('wp_ajax_nopriv_my_kboard_exif_read_data', 'my_kboard_exif_read_data');
        function my_kboard_exif_read_data(){
            check_ajax_referer('my_kboard_exif_read_data_nonce', 'security');
            $src = isset($_POST['src'])?sanitize_text_field($_POST['src']):'';
            if($src){
                $url = parse_url($src);
                if(isset($url['path']) && $url['path']){
                    $upload_dir = wp_upload_dir();
                    $img_file = $upload_dir['basedir'] . end(explode('/wp-content/uploads', $url['path']));
                    if(file_exists($img_file)){
                        $exif = exif_read_data($img_file);
                        if($exif){
                            echo json_encode($exif);
                            wp_die();
                        }
                    }
                }
            }
            echo json_encode(array('error'=>'Image file does not exist.'));
            wp_die();
        }
    }

     

    그리고 사용하시는 스킨의 document.php 파일 하단에 아래 코드를 추가해서 테스트 해보세요.

    /wp-content/plugins/kboard/skin/사용중인스킨/document.php 파일입니다.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    <script>
    var my_kboard_exif_read_data_nonce = '<?php echo wp_create_nonce('my_kboard_exif_read_data_nonce')?>';
    jQuery(document).ready(function(){
        jQuery('.kboard-content img').each(function(){
            var img = jQuery(this);
            jQuery.post('<?php echo admin_url('admin-ajax.php');?>', {action:'my_kboard_exif_read_data', security:my_kboard_exif_read_data_nonce, src:img.attr('src')}, function(res){
                if(!res.error){
                    var ul = jQuery('<ul></ul>');
     
                    if(res.ApertureFNumber) ul.append(jQuery('<li></li>').text('조리개:' + res.ApertureFNumber));
                    if(res.Model) ul.append(jQuery('<li></li>').text('모델:' + res.Model));
                    if(res.DateTimeOriginal) ul.append(jQuery('<li></li>').text('날짜:' + res.DateTimeOriginal));
                    if(res.ISOSpeedRatings) ul.append(jQuery('<li></li>').text('ISO:' + res.ISOSpeedRatings));
                    if(res.FocalLength) ul.append(jQuery('<li></li>').text('초점거리:' + eval(res.FocalLength)));
                    if(res.ExposureTime) ul.append(jQuery('<li></li>').text('노출시간:' + res.ExposureTime));
     
                    if(res.GPSLatitude && res.GPSLongitude){
                        var map_zoom = 11;
                        var map_size_width = 300;
                        var map_size_height = 200;
     
                        var deg = eval(res.GPSLatitude[0]);
                        var min = eval(res.GPSLatitude[1]);
                        var sec = eval(res.GPSLatitude[2]);
                        res.gps_lat = deg + ((min/60) + (sec/3600));
     
                        deg = eval(res.GPSLongitude[0]);
                        min = eval(res.GPSLongitude[1]);
                        sec = eval(res.GPSLongitude[2]);
                        res.gps_long = deg + ((min/60) + (sec/3600));
     
                        ul.append(jQuery('<li></li>').text('GPS:' + res.gps_lat + ',' + res.gps_long));
                        ul.append(jQuery('<li></li>').append(jQuery('<a href="https://www.google.com/maps/place/'+res.gps_lat+','+res.gps_long+'" onclick="window.open(this.href);return false;"><img src="https://maps.googleapis.com/maps/api/staticmap?zoom='+map_zoom+'&amp;size='+map_size_width+'x'+map_size_height+'&amp;maptype=roadmap&#10;&amp;markers=color:blue%7Clabel:S%7C'+res.gps_lat+','+res.gps_long+'&amp;sensor=false" alt="" width="'+map_size_width+'" height="'+map_size_height+'" style="vertical-align:top;"></a>')));
                    }
     
                    img.after(ul);
                }
            }, 'json');
        });
    });
    </script>

     

    자바스크립트(또는 jQuery)와 PHP에 대해서 좀 아시면 코드를 수정하시는데 수월 할 듯합니다.

  • 소스 코드 너무 감사합니다. 

    적용해서 사용해 보도록 하겠습니다 

    코드 적용후 글 올릴께요 

    너무 감사합니다. ! 

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요

AI 상담