0

我想处理所有附件,但不重新生成缩略图。现在我正在使用 wp_generate_attachment_metadata()..但是由于缩略图创建,这需要很长时间来执行所有帖子附件。我只想序列化元数据数组以加快执行速度。

4

1 回答 1

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 );
}
于 2012-04-19T15:13:11.390 回答