programing

워드프레스 webp 이미지 미리보기

lovejava 2023. 9. 26. 19:11

워드프레스 webp 이미지 미리보기

저는 웹업로드를 허용하기 위해 다음 코드를 사용하여 워드프레스를 업데이트하였습니다.

function webp_upload_mimes( $existing_mimes ) {
    $existing_mimes['webp'] = 'image/webp';
    return $existing_mimes;
}
add_filter( 'mime_types', 'webp_upload_mimes' );

잘 작동하지만 표시된 것처럼 webp 이미지는 미디어 선택기에 미리보기를 표시하지 않습니다.

enter image description here

webp 미리보기를 렌더링하기 위해 워드 프레스를 강제로 사용할 수 있는 방법이 있습니까?제 사이트가 완료될 때쯤이면 수백 개의 웹p 이미지가 있을 수도 있기 때문에 선택할 때 웹p 이미지를 볼 수 없는 것은 큰 고통이 될 수 있습니다!

2021년 7월 업데이트

WordPress 버전 5.8 이후부터는 웹P 이미지를 현재 JPEG 또는 PNG 이미지처럼 WordPress에 업로드하고 사용할 수 있습니다(호스팅 서비스가 웹P를 지원하는 한).이미지에 대한 WebP 형식으로 전환하면 사이트 성능과 사이트 방문자 경험이 향상됩니다.
https://make.wordpress.org/core/2021/06/07/wordpress-5-8-adds-webp-support/


미디어 매니저에서 썸네일을 보여줄 수 있는 해결책을 찾았습니다.다음 코드를 추가해야 합니다.functions.php사용자의 활동 테마:

//enable upload for webp image files.
function webp_upload_mimes($existing_mimes) {
    $existing_mimes['webp'] = 'image/webp';
    return $existing_mimes;
}
add_filter('mime_types', 'webp_upload_mimes');

//enable preview / thumbnail for webp image files.
function webp_is_displayable($result, $path) {
    if ($result === false) {
        $displayable_image_types = array( IMAGETYPE_WEBP );
        $info = @getimagesize( $path );

        if (empty($info)) {
            $result = false;
        } elseif (!in_array($info[2], $displayable_image_types)) {
            $result = false;
        } else {
            $result = true;
        }
    }

    return $result;
}
add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);

webp_is_displayable함수는 후크를 사용하고 있으며 파일이 (on)인지 확인합니다.$path)는webp이미지 파일.확인하기 위해webp함수가 상수를 사용하는 image file.

세바스찬 브로쉬가 제안한 해결책은 여전히 효과가 있습니다.하지만 S_R이 언급한 것처럼, 오래된 웹p 이미지는 작동하는 미리보기가 없을 것입니다.이를 위해 워드프레스 플러그인 "Force Regenerate Summails"를 사용하여 오래된 이미지를 다시 로드하고 미리보기를 만들 수 있습니다.

WordPress에서 webp를 미디어/라이브러리에 업로드할 수 있도록 하려면 다음 코드를 사용할 수 있습니다.

//** Enable upload for webp image files.
function webp_upload_mimes($existing_mimes) {
    $existing_mimes['webp'] = 'image/webp';
    return $existing_mimes;
}
add_filter('mime_types', 'webp_upload_mimes');

언급URL : https://stackoverflow.com/questions/54442929/wordpress-webp-image-previews