当前位置: 首页>>代码示例>>PHP>>正文


PHP file_is_displayable_image函数代码示例

本文整理汇总了PHP中file_is_displayable_image函数的典型用法代码示例。如果您正苦于以下问题:PHP file_is_displayable_image函数的具体用法?PHP file_is_displayable_image怎么用?PHP file_is_displayable_image使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了file_is_displayable_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: file_gallery_add_media_actions

function file_gallery_add_media_actions($actions, $post)
{
    if (!isset($actions['sis-regenerate']) && !isset($action['regenerate_thumbnails']) && file_is_displayable_image(get_attached_file($post->ID))) {
        $actions['file_gallery_regenerate'] = '<a href="#" id="file_gallery_regenerate-' . $post->ID . '" class="file_gallery_regenerate">' . __('Regenerate', 'file-gallery') . '</a>';
    }
    return $actions;
}
开发者ID:kyme-online,项目名称:Ramesh-Photography,代码行数:7,代码来源:regenerate-images.php

示例2: my_save_extra_profile_fields

 function my_save_extra_profile_fields($user_id)
 {
     if (!current_user_can('edit_user', $user_id)) {
         return false;
     }
     $upload = $_FILES['profile_image'];
     $uploads = wp_upload_dir();
     if ($upload['tmp_name'] && file_is_displayable_image($upload['tmp_name'])) {
         // handle the uploaded file
         $overrides = array('test_form' => false);
         $file = wp_handle_upload($upload, $overrides);
         $file["file"] = $uploads["subdir"] . "/" . basename($file["url"]);
         if ($file) {
             //remove previous uploaded file
             $author_profile_image = $this->get_author_profile_image($user_id);
             @unlink($author_profile_image["file"]);
             update_user_meta($user_id, 'profile_image', $file);
         }
     }
     if (isset($_POST['remove_image'])) {
         $author_profile_image = $this->get_author_profile_image($user_id);
         @unlink($author_profile_image["file"]);
         update_user_meta($user_id, 'profile_image', false);
     }
 }
开发者ID:phucanh92,项目名称:vietlong,代码行数:25,代码来源:profile-image.php

示例3: wp_generate_attachment_metadata

/**
 * wp_generate_attachment_metadata() - Generate post Image attachment Metadata
 *
 * @package WordPress
 * @internal Missing Long Description
 * @param	int		$attachment_id	Attachment Id to process
 * @param	string	$file	Filepath of the Attached image
 * @return	mixed			Metadata for attachment
 *
 */
function wp_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_shrink_dimensions($metadata['width'], $metadata['height']);
        $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
        $metadata['file'] = $file;
        // make thumbnails and other intermediate sizes
        $sizes = array('thumbnail', 'medium');
        $sizes = apply_filters('intermediate_image_sizes', $sizes);
        foreach ($sizes as $size) {
            $resized = image_make_intermediate_size($file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop"));
            if ($resized) {
                $metadata['sizes'][$size] = $resized;
            }
        }
        // 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);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:38,代码来源:image.php

示例4: wp_generate_attachment_metadata

 public function wp_generate_attachment_metadata($metadata, $attachment_id)
 {
     $attachment = get_attached_file($attachment_id);
     if (!preg_match('!^image/!', get_post_mime_type($attachment_id)) || !file_is_displayable_image($attachment)) {
         return $metadata;
     }
     $image_sizes = Helper::get_image_sizes();
     foreach ($image_sizes as $size_name => $size_attributes) {
         if (!empty($metadata['sizes'][$size_name])) {
             continue;
         }
         $image = wp_get_image_editor($attachment);
         if (is_wp_error($image)) {
             continue;
         }
         $resized = $image->resize($size_attributes['width'], $size_attributes['height'], $size_attributes['crop']);
         $image_size = $image->get_size();
         if (!is_wp_error($resized) && !empty($image_size)) {
             $filename = wp_basename($image->generate_filename());
             $extension = pathinfo($filename, PATHINFO_EXTENSION);
             $mime_type = $this->get_mime_type($extension);
             $metadata['sizes'][$size_name] = array('file' => $filename, 'width' => $image_size['width'], 'height' => $image_size['height'], 'mime-type' => $mime_type);
         }
     }
     return $metadata;
 }
开发者ID:brutalenemy666,项目名称:carbon-image-library,代码行数:26,代码来源:WP_Media.php

示例5: test_is_displayable_image_negative

 function test_is_displayable_image_negative()
 {
     // these are image files but aren't suitable for web pages because of compatibility or size issues
     $files = array('test-image.pct', 'test-image.tga', 'test-image.sgi', 'test-image.tiff', 'test-image-lzw.tiff', 'test-image.jp2', 'test-image.psd', 'test-image-zip.tiff');
     foreach ($files as $file) {
         $this->assertFalse(file_is_displayable_image(DIR_TESTDATA . '/images/' . $file), "file_is_valid_image({$file}) should return false");
     }
 }
开发者ID:CompositeUK,项目名称:clone.WordPress-Develop,代码行数:8,代码来源:functions.php

示例6: sp_generate_attachment_metadata

function sp_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_shrink_dimensions($metadata['width'], $metadata['height']);
        $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
        // Make the file path relative to the upload dir
        $metadata['file'] = $attachment->post_title;
        // make thumbnails and other intermediate sizes
        global $_wp_additional_image_sizes;
        $temp_sizes = array('thumbnail', 'medium', 'large');
        // Standard sizes
        if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes)) {
            $temp_sizes = array_merge($temp_sizes, array_keys($_wp_additional_image_sizes));
        }
        $temp_sizes = apply_filters('intermediate_image_sizes', $temp_sizes);
        foreach ($temp_sizes as $s) {
            $sizes[$s] = array('width' => '', 'height' => '', 'crop' => FALSE);
            if (isset($_wp_additional_image_sizes[$s]['width'])) {
                $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']);
            } else {
                $sizes[$s]['width'] = get_option("{$s}_size_w");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['height'])) {
                $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']);
            } else {
                $sizes[$s]['height'] = get_option("{$s}_size_h");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['crop'])) {
                $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']);
            } else {
                $sizes[$s]['crop'] = get_option("{$s}_crop");
            }
            // For default sizes set in options
        }
        $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes);
        foreach ($sizes as $size => $size_data) {
            $resized = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']);
            if ($resized) {
                $metadata['sizes'][$size] = $resized;
            }
        }
        // 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);
}
开发者ID:voodoobettie,项目名称:staypressproperty,代码行数:56,代码来源:functions.php

示例7: hack_wp_generate_attachment_metadata

function hack_wp_generate_attachment_metadata($metadata, $attachment_id)
{
    if (!isset($metadata['file'])) {
        return $metadata;
    }
    $attachment = get_post($attachment_id);
    $uploadPath = wp_upload_dir();
    $file = path_join($uploadPath['basedir'], $metadata['file']);
    $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);
        // make thumbnails and other intermediate sizes
        global $_wp_additional_image_sizes;
        foreach (get_intermediate_image_sizes() as $s) {
            $sizes[$s] = array('width' => '', 'height' => '', 'crop' => FALSE);
            if (isset($_wp_additional_image_sizes[$s]['width'])) {
                $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']);
            } else {
                $sizes[$s]['width'] = get_option("{$s}_size_w");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['height'])) {
                $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']);
            } else {
                $sizes[$s]['height'] = get_option("{$s}_size_h");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['crop'])) {
                $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']);
            } else {
                $sizes[$s]['crop'] = get_option("{$s}_crop");
            }
            // For default sizes set in options
        }
        foreach ($sizes as $size => $size_data) {
            $resized = hack_image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop'], $size);
            if ($resized) {
                $metadata['sizes'][$size] = $resized;
            }
        }
        // fetch additional metadata from exif/iptc
        $image_meta = wp_read_image_metadata($file);
        if ($image_meta) {
            $metadata['image_meta'] = $image_meta;
        }
    }
    return $metadata;
}
开发者ID:atomita,项目名称:wordpress-thumbnail-filename-changer,代码行数:54,代码来源:thumbnail-filename-changer.php

示例8: wp_generate_attachment_metadata

/**
 * Generate post thumbnail attachment meta data.
 *
 * @since 2.1.0
 *
 * @param int $attachment_id Attachment Id to process.
 * @param string $file Filepath of the Attached image.
 * @return mixed Metadata for attachment.
 */
function wp_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];

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

		// make thumbnails and other intermediate sizes
		global $_wp_additional_image_sizes;

		foreach ( get_intermediate_image_sizes() as $s ) {
			$sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false );
			if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
				$sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
			else
				$sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
			if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
				$sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
			else
				$sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
			if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
				$sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
			else
				$sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
		}

		$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );

		if ( $sizes ) {
			$editor = wp_get_image_editor( $file );

			if ( ! is_wp_error( $editor ) )
				$metadata['sizes'] = $editor->multi_resize( $sizes );
		} else {
			$metadata['sizes'] = array();
		}

		// 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 );
}
开发者ID:pauEscarcia,项目名称:AIMM,代码行数:60,代码来源:IMAGE.PHP

示例9: enforce_attachment_size

 /**
  * Enforce Attachment Size
  *
  * @param array $data Sanitized post data.
  * @param array $postarr Raw post data.
  **/
 public function enforce_attachment_size($data, $postarr)
 {
     // File path.
     $file = $postarr['file'];
     // Check if we are dealing with an attachment of type image.
     if ('attachment' === $data['post_type'] && preg_match('!^image/!', $postarr['post_mime_type']) && \file_is_displayable_image($file)) {
         $resize_dimensions = $this->resize_dimensions();
         // Do the actual resize of the original attachment.
         if (!empty($resize_dimensions)) {
             $this->resize_original($postarr['file'], $resize_dimensions);
         }
     }
     return $data;
 }
开发者ID:xipasduarte,项目名称:wp-resize-original,代码行数:20,代码来源:ResizeOriginal.php

示例10: mief_slideshow_detect_upload

/**
 * Detect file upload and handle it
 *
 * return void
 */
function mief_slideshow_detect_upload()
{
    if (!empty($_FILES)) {
        global $wpdb;
        if (file_is_displayable_image($_FILES['mief_slideshow_file']['tmp_name'])) {
            $overrides = array('test_form' => false);
            $file = wp_handle_upload($_FILES['mief_slideshow_file'], $overrides);
            if ($file) {
                $table_name = $wpdb->prefix . "mief_slideshow";
                $result = $wpdb->insert($table_name, array('filename' => serialize($file), 'url' => '', 'weight' => 1, 'slideshow_id' => mief_get_slideshow_mid()));
            }
        }
    }
}
开发者ID:rikvanderkemp,项目名称:mief-slideshow,代码行数:19,代码来源:admin.php

示例11: generate_attachment_metadata

 /**
  * generate attachment metadata but DO NOT create thumbnails etc.
  * @param int $attachment_id
  * @param string $file
  *        	absolute file path
  */
 public static function 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);
         // work with some watermark plugin
         $metadata = apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id);
     }
     return $metadata;
 }
开发者ID:vihoangson,项目名称:vihoangson.vus.vn,代码行数:23,代码来源:util.class.php

示例12: wp_generate_attachment_metadata_custom

/**
 * Generate post thumbnail attachment meta data.
 *
 * @since 2.1.0
 *
 * @param int $attachment_id Attachment Id to process.
 * @param string $file Filepath of the Attached image.
 * @return mixed Metadata for attachment.
 */
function wp_generate_attachment_metadata_custom($attachment_id, $file, $thumbnails = NULL)
{
    $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);
        $sizes = ajax_thumbnail_rebuild_get_sizes();
        $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes);
        foreach ($sizes as $size => $size_data) {
            if (isset($thumbnails) && !in_array($size, $thumbnails)) {
                $intermediate_size = image_get_intermediate_size($attachment_id, $size_data['name']);
            } else {
                $intermediate_size = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']);
            }
            if ($intermediate_size) {
                $metadata['sizes'][$size] = $intermediate_size;
            }
        }
        // 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);
}
开发者ID:vicch,项目名称:wp-about,代码行数:41,代码来源:ajax-thumbnail-rebuild.php

示例13: ed_delete_attachment

function ed_delete_attachment($attach_id)
{
    $meta = wp_get_attachment_metadata($attach_id);
    $sizes = $meta['sizes'];
    if (!sizes || !is_array($sizes)) {
        return $meta;
    }
    $uploads = wp_upload_dir();
    $pi = pathinfo($meta['file']);
    $x2_filename = trailingslashit($uploads['basedir']) . $pi['dirname'] . '/' . $pi['filename'] . '@2x.' . $pi['extension'];
    if (file_exists($x2_filename) && file_is_displayable_image($x2_filename)) {
        unlink($x2_filename);
    }
}
开发者ID:ats05,项目名称:Synapse,代码行数:14,代码来源:functions.php

示例14: wp_generate_attachment_metadata

/**
 * Generate post thumbnail attachment meta data.
 *
 * @since 2.1.0
 *
 * @param int $attachment_id Attachment Id to process.
 * @param string $file Filepath of the Attached image.
 * @return mixed Metadata for attachment.
 */
function wp_generate_attachment_metadata($attachment_id, $file)
{
    $attachment = get_post($attachment_id);
    $metadata = array();
    $support = false;
    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];
        // Make the file path relative to the upload dir
        $metadata['file'] = _wp_relative_upload_path($file);
        // make thumbnails and other intermediate sizes
        global $_wp_additional_image_sizes;
        $sizes = array();
        foreach (get_intermediate_image_sizes() as $s) {
            $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false);
            if (isset($_wp_additional_image_sizes[$s]['width'])) {
                $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']);
            } else {
                $sizes[$s]['width'] = get_option("{$s}_size_w");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['height'])) {
                $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']);
            } else {
                $sizes[$s]['height'] = get_option("{$s}_size_h");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['crop'])) {
                $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']);
            } else {
                $sizes[$s]['crop'] = get_option("{$s}_crop");
            }
            // For default sizes set in options
        }
        $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes);
        if ($sizes) {
            $editor = wp_get_image_editor($file);
            if (!is_wp_error($editor)) {
                $metadata['sizes'] = $editor->multi_resize($sizes);
            }
        } else {
            $metadata['sizes'] = array();
        }
        // fetch additional metadata from exif/iptc
        $image_meta = wp_read_image_metadata($file);
        if ($image_meta) {
            $metadata['image_meta'] = $image_meta;
        }
    } elseif (preg_match('#^video/#', get_post_mime_type($attachment))) {
        $metadata = wp_read_video_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:video') && post_type_supports('attachment:video', 'thumbnail');
    } elseif (preg_match('#^audio/#', get_post_mime_type($attachment))) {
        $metadata = wp_read_audio_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:audio') && post_type_supports('attachment:audio', 'thumbnail');
    }
    if ($support && !empty($metadata['image']['data'])) {
        $ext = '.jpg';
        switch ($metadata['image']['mime']) {
            case 'image/gif':
                $ext = '.gif';
                break;
            case 'image/png':
                $ext = '.png';
                break;
        }
        $basename = str_replace('.', '-', basename($file)) . '-image' . $ext;
        $uploaded = wp_upload_bits($basename, '', $metadata['image']['data']);
        if (false === $uploaded['error']) {
            $attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => '');
            $sub_attachment_id = wp_insert_attachment($attachment, $uploaded['file']);
            $attach_data = wp_generate_attachment_metadata($sub_attachment_id, $uploaded['file']);
            wp_update_attachment_metadata($sub_attachment_id, $attach_data);
            update_post_meta($attachment_id, '_thumbnail_id', $sub_attachment_id);
        }
    }
    // remove the blob of binary data from the array
    unset($metadata['image']['data']);
    return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id);
}
开发者ID:pankajsinghjarial,项目名称:SYLC-AMERICAN,代码行数:89,代码来源:image.php

示例15: pods_image_resize

/**
 * Resize an image on demand
 *
 * @param int $attachment_id Attachment ID
 * @param string|array $size Size to be generated
 *
 * @return boolean Image generation result
 *
 * @since 2.3
 */
function pods_image_resize($attachment_id, $size)
{
    $size_data = array();
    // Basic image size string
    if (!is_array($size)) {
        global $wp_image_sizes;
        // Registered image size
        if (isset($wp_image_sizes[$size]) && !empty($wp_image_sizes[$size])) {
            $size_data = $wp_image_sizes[$size];
        } elseif (preg_match('/[0-9]+x[0-9]+/', $size) || preg_match('/[0-9]+x[0-9]+x[0-1]/', $size)) {
            $size = explode('x', $size);
            $size_data = array('width' => (int) $size[0], 'height' => (int) $size[1], 'crop' => (int) (isset($size[2]) ? $size[2] : 1));
            $size = $size_data['width'] . 'x' . $size_data['height'];
        }
    } elseif (2 <= count($size)) {
        if (isset($size['width'])) {
            $size_data = $size;
        } else {
            $size_data = array('width' => (int) $size[0], 'height' => (int) $size[1], 'crop' => (int) (isset($size[2]) ? $size[2] : 1));
        }
        $size = $size_data['width'] . 'x' . $size_data['height'];
    }
    if (empty($size_data)) {
        return false;
    }
    require_once ABSPATH . 'wp-admin/includes/image.php';
    $attachment = get_post($attachment_id);
    $file = get_attached_file($attachment_id);
    if ($file && file_exists($file)) {
        $metadata = wp_get_attachment_metadata($attachment_id);
        if (!empty($metadata) && preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) {
            $editor = wp_get_image_editor($file);
            if (!is_wp_error($editor)) {
                $metadata['sizes'] = array_merge($metadata['sizes'], $editor->multi_resize(array($size => $size_data)));
                wp_update_attachment_metadata($attachment_id, $metadata);
                return true;
            }
        }
    }
    return false;
}
开发者ID:dylansmithing,项目名称:leader-of-rock-wordpress,代码行数:51,代码来源:media.php


注:本文中的file_is_displayable_image函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。