• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP file_is_displayable_image函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: generate_gmedia_metadata

 /**
  * Generate gmedia meta data.
  *
  * @see wp_generate_attachment_metadata()
  *
  * @param int   $media_id Gmedia Id to process.
  * @param array $fileinfo from fileinfo() function
  *
  * @return mixed Metadata for media.
  */
 function generate_gmedia_metadata($media_id, $fileinfo = array())
 {
     global $gmCore;
     $media = $this->get_gmedia($media_id);
     if (empty($fileinfo)) {
         $fileinfo = $gmCore->fileinfo($media->gmuid, false);
     }
     $metadata = array();
     require_once ABSPATH . 'wp-admin/includes/image.php';
     if (preg_match('!^image/!', $media->mime_type) && file_is_displayable_image($fileinfo['filepath'])) {
         $imagesize = getimagesize($fileinfo['filepath']);
         $metadata['web'] = array('width' => $imagesize[0], 'height' => $imagesize[1]);
         $imagesize = getimagesize($fileinfo['filepath_original']);
         $metadata['original'] = array('width' => $imagesize[0], 'height' => $imagesize[1]);
         $imagesize = getimagesize($fileinfo['filepath_thumb']);
         $metadata['thumb'] = array('width' => $imagesize[0], 'height' => $imagesize[1]);
         $metadata['file'] = $this->_gm_relative_upload_path($fileinfo['filepath']);
         // fetch additional metadata from exif/iptc
         $image_meta = $gmCore->wp_read_image_metadata($fileinfo['filepath_original']);
         if ($image_meta) {
             $metadata['image_meta'] = $image_meta;
         }
     } elseif (preg_match('#^video/#', $media->mime_type)) {
         $metadata = $gmCore->wp_read_video_metadata($fileinfo['filepath']);
     } elseif (preg_match('#^audio/#', $media->mime_type)) {
         $metadata = $gmCore->wp_read_audio_metadata($fileinfo['filepath']);
     }
     return apply_filters('generate_gmedia_metadata', $metadata, $media_id);
 }
开发者ID:HugoLS,项目名称:Variation,代码行数:39,代码来源:db.connect.php


示例17: generate_metadata

 /**
  * Generate meta data for the media
  *
  * @since 1.0.0
  *	
  * @access  private
  * @param int $attachment_id Media ID  to process.
  * @param string $file Filepath of the Attached image.
  * 
  * @return mixed Metadata for attachment.
  */
 public function generate_metadata($attachment_id, $file)
 {
     $attachment = get_post($attachment_id);
     $mime_type = get_post_mime_type($attachment);
     $metadata = array();
     if (preg_match('!^image/!', $mime_type) && 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);
         //get the registered media sizes
         $sizes = mpp_get_media_sizes();
         $sizes = apply_filters('mpp_intermediate_image_sizes', $sizes, $attachment_id);
         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/#', $mime_type)) {
         $metadata = wp_read_video_metadata($file);
     } elseif (preg_match('#^audio/#', $mime_type)) {
         $metadata = wp_read_audio_metadata($file);
     }
     $dir_path = trailingslashit(dirname($file)) . 'covers';
     $url = wp_get_attachment_url($attachment_id);
     $base_url = str_replace(wp_basename($url), '', $url);
     //processing for audio/video cover
     if (!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 = $this->upload_bits($basename, $metadata['image']['data'], array('path' => $dir_path, 'url' => $base_url));
         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 = $this->generate_metadata($sub_attachment_id, $uploaded['file']);
             wp_update_attachment_metadata($sub_attachment_id, $attach_data);
             //if the option is set to set post thumbnail
             if (mpp_get_option('set_post_thumbnail')) {
                 mpp_update_media_meta($attachment_id, '_thumbnail_id', $sub_attachment_id);
             }
             //set the cover id
             mpp_update_media_cover_id($attachment_id, $sub_attachment_id);
         }
     }
     // remove the blob of binary data from the array
     if (isset($metadata['image']['data'])) {
         unset($metadata['image']['data']);
     }
     return apply_filters('mpp_generate_metadata', $metadata, $attachment_id);
 }
开发者ID:markc,项目名称:mediapress,代码行数:78,代码来源:class-mpp-local-storage.php


示例18: gllr_wp_generate_attachment_metadata

 function gllr_wp_generate_attachment_metadata($attachment_id, $file, $metadata)
 {
     $attachment = get_post($attachment_id);
     $gllr_options = get_option('gllr_options');
     add_image_size('album-thumb', $gllr_options['gllr_custom_size_px'][0][0], $gllr_options['gllr_custom_size_px'][0][1], true);
     add_image_size('photo-thumb', $gllr_options['gllr_custom_size_px'][1][0], $gllr_options['gllr_custom_size_px'][1][1], true);
     $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;
         $image_size = array('album-thumb', 'photo-thumb', 'thumbnail');
         /*get_intermediate_image_sizes();*/
         foreach ($image_size 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 = gllr_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:kityan,项目名称:gallery-wordpress-plugin,代码行数:55,代码来源:gallery-plugin.php


示例19: generate_thumb_missing

 /**
  * Regenerate missing image dimensions for a particular attachment
  * @param (int) attachment ID
  * @return (array) new metadata for actual image
  **/
 public function generate_thumb_missing($att_id)
 {
     // Fetch the attachment
     $att_raw = get_posts(array('include' => $att_id, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
     $att = $att_raw[0];
     $file = get_attached_file($att_id);
     // COMPLETE THIS SHIT.
     $metadata = array();
     if (preg_match('!^image/!', get_post_mime_type($att)) && 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
         }
         $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes);
         // Only generate image if it does not already exist
         $att_meta = wp_get_attachment_metadata($att_id);
         foreach ($sizes as $size => $size_data) {
             // Size already exists
             if (isset($att_meta['sizes'][$size]) && file_exists($this->imageTrySize($file, $size_data['width'], $size_data['height']))) {
                 $metadata['sizes'][$size] = $att_meta['sizes'][$size];
             } else {
                 // Generate new image
                 $resized = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']);
                 if ($resized) {
                     $metadata['sizes'][$size] = $resized;
                 }
             }
         }
         // Get image meta and update database manually
         $metadata['image_meta'] = wp_read_image_metadata($file);
         update_post_meta($att_id, "_wp_attachment_metadata", $metadata);
     }
     return $att;
 }
开发者ID:spokencode,项目名称:bophillips,代码行数:65,代码来源:onet-regen-thumbnails.php


示例20: add_media_to_content

 function add_media_to_content($post_id, $file, $more_than_1 = false)
 {
     $post_fields = array('post_title', 'post_content', 'post_excerpt');
     $image_file = file_is_displayable_image($file['new_file']);
     $html = $file['url'];
     if (isset($file['acf'])) {
         update_field($file['acf']['field_id'], $file['new_id'], $post_id);
     } elseif (in_array($file['field'], $post_fields)) {
         $tag = '#_gc_file_name_' . $file['counter'] . '#';
         $post = get_post($post_id);
         if ($image_file) {
             $html = '<a href="' . $file['url'] . '"><img src="' . $file['url'] . '" alt="' . esc_attr($file['title']) . '" /></a>' . &qu 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP file_is_draft_area_limit_reached函数代码示例发布时间:2022-05-15
下一篇:
PHP file_icon函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap