2014-03-26 3 views
2

워드 프레스 : 난 항상 큰 사이즈의 이미지가 필요변경 이미지의 이름은

1 -> thumbnailsize (150x150) 
2 -> Medium size (1024x768) 
3 -> Large size (1920x1080) 
4 -> Original size (---x---) 

하지만 때 1620x1080 크기의 이미지를 업로드하면 Wordpress에서 이미지 이름을 some-image-1620x1080.jpg으로 변경합니다.

나는 어떤 식 으로든 일부 이미지 - large.jpg-일부 이미지 - 1920x1080.jpg에서 참고 ImageName를 변경할 수 있습니까?

답변

1

당신은 파일 업로드를 처리 및 필터 wp_handle_upload_prefilter에 중독 될 것이다, 당신의 functions.php 파일에서 함수를 작성해야합니다 :

add_filter('wp_handle_upload_prefilter', 'wp_rename_large_images', 1, 1); 
//Check to see if function name is unique 
if (!function_exists("wp_rename_large_images")) { 
function wp_rename_large_images($file){ 
    //Get image size 
    $img = getimagesize($file['tmp_name']); 
    //Image dimensions 
    $width = $img[0]; 
    $height = $img[1]; 
    //Check to see if image is large enough to change the file name 
    if ($width > 1200 || $height > 1080) { 
    //Modify the file name WITH an extension 
    $ext = pathinfo($file['name'], PATHINFO_EXTENSION); 
    //Build the new file name (remove the old extension - last 3 characters from the file name, i.e. jpg, gif, png, bmp, etc.) 
    $file['name'] = substr($file['name'], -3) . '-large'. $ext; 
    } 
    return $file; 
} 
} 

이 문서 here를 참조하십시오.

+0

: http://cl.ly/image/031M2b1U1m1Y 파일에 문제가있을 수 있습니다 신장? –

+0

이상한 점이 있습니다 ... 다른 MIME 형식이 아닌 이미지를 업로드 하시겠습니까? – bodi0

+0

확장자가 이미 파일 이름에 있으므로 $ filetype [ 'ext']은 필요하지 않습니다. 그것이 문제였습니다. –

0

아직이 문제에 대한 특정 해결책을 찾지 못했지만 일부 사람들은 업로드 된 파일의 이름을 변경할 수 없다고 주장하며 일부 파일 만 추가합니다. 지금 내가 사용한 것은 Maxon의 Gallery Theme 플러그인으로 두 개의 개별 데이터 경로에서 엄지 손톱과 대형 이미지를 가져와 내 전체 문제를 해결했습니다. 플러그인은 매우 가볍고 갤러리를 위해 완벽하게 작동합니다.

플러그인은 여기에서 찾을 수 있습니다 : 나는 스크립트를 시도하고 이미지 업로드에 오류가 점점 계속 http://wordpress.org/plugins/gallery-theme/