2012-04-19 77 views
0

我想處理所有的附件,但沒有再次重新生成縮略圖。現在我正在使用wp_generate_attachment_metadata()..但是這需要很長時間來執行所有的附件,因爲thumbanail創作。我只是想要序列化元數據數組以加快執行速度。wordpress圖像附件元數據不生成縮略圖

回答

4

你可以寫你自己的這個函數的版本不大拇指一代,看看這裏: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/image.php#L80

例如:

function my_generate_attachment_metadata($attachment_id, $file) { 
    $attachment = get_post($attachment_id); 

    $metadata = array(); 
    if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { 
     $imagesize = getimagesize($file); 
     $metadata['width'] = $imagesize[0]; 
     $metadata['height'] = $imagesize[1]; 
     list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); 
     $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; 

     // Make the file path relative to the upload dir 
     $metadata['file'] = _wp_relative_upload_path($file); 

     // fetch additional metadata from exif/iptc 
     $image_meta = wp_read_image_metadata($file); 
     if ($image_meta) 
      $metadata['image_meta'] = $image_meta; 
    } 

    return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); 
} 
+0

是的,但有喜歡傳球真/假的任何其他選項函數的參數?我不想重寫相同的代碼。 – Madan 2012-04-19 15:16:17

+1

看看源代碼,沒有選擇。回答更新示例 – soju 2012-04-19 15:17:54

+0

謝謝,但我會錯過$ arr ['sizes'] – Madan 2012-04-19 18:24:40