wordpress图像附件元数据,不生成缩略图

时间:2012-04-19 14:57:58

标签: wordpress

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

1 个答案:

答案 0 :(得分: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 );
}