本文整理汇总了PHP中wp_get_attachment_thumb_file函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_attachment_thumb_file函数的具体用法?PHP wp_get_attachment_thumb_file怎么用?PHP wp_get_attachment_thumb_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_attachment_thumb_file函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: image_downsize
function image_downsize($id, $size = 'medium')
{
if (!wp_attachment_is_image($id)) {
return false;
}
$img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
$width = $height = 0;
// plugins can use this to provide resize services
if ($out = apply_filters('image_downsize', false, $id, $size)) {
return $out;
}
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
$width = $intermediate['width'];
$height = $intermediate['height'];
} elseif ($size == 'thumbnail') {
// fall back to the old thumbnail
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
$width = $info[0];
$height = $info[1];
}
}
if (!$width && !$height && isset($meta['width'], $meta['height'])) {
// any other type: use the real image and constrain it
list($width, $height) = image_constrain_size_for_editor($meta['width'], $meta['height'], $size);
}
if ($img_url) {
return array($img_url, $width, $height);
}
return false;
}
示例2: downsize
function downsize($out, $id, $size)
{
$img_url = wp_get_attachment_url($id);
$img_path = get_attached_file($id);
$meta = wp_get_attachment_metadata($id);
$width = $height = 0;
$is_intermediate = false;
$img_url_basename = wp_basename($img_url);
$img_path_basename = wp_basename($img_path);
// extract filter from size request
if (!is_string($size)) {
return $out;
}
$size_bits = explode(':', $size);
$filter = isset($size_bits[1]) ? $size_bits[1] : false;
$size = isset($size_bits[0]) ? $size_bits[0] : false;
// start the reactor
if ($filter) {
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
$img_path = str_replace($img_path_basename, $intermediate['file'], $img_path);
$width = $intermediate['width'];
$height = $intermediate['height'];
$is_intermediate = true;
} elseif ($size == 'thumbnail') {
// fall back to the old thumbnail
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
$img_path = str_replace($img_path_basename, wp_basename($thumb_file), $img_path);
$width = $info[0];
$height = $info[1];
$is_intermediate = true;
}
}
if (!$width && !$height && isset($meta['width'], $meta['height'])) {
// any other type: use the real image
$width = $meta['width'];
$height = $meta['height'];
}
if ($img_url && $img_path) {
$input = $img_path;
$output = $this->filtered_url($input, $filter);
// generate filtered thumb
if (!file_exists($output)) {
$this->filter($filter, $input, $output);
}
// point to our new file
$img_url = $this->filtered_url($img_url, $filter);
// we have the actual image size, but might need to further constrain it if content_width is narrower
list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
return array($img_url, $width, $height, $is_intermediate);
}
// don't continue the downsize funtion
return true;
}
return $out;
}
示例3: __wp_supercustom_cms_image_downsize
/**
* Uses WordPress filter for image_downsize, kill wp-image-dimension
* code by Andrew Rickmann
* http://www.wp-fun.co.uk/
* @param $value, $id, $size
*/
function __wp_supercustom_cms_image_downsize($value = FALSE, $id = 0, $size = 'medium')
{
if (!wp_attachment_is_image($id)) {
return FALSE;
}
$img_url = wp_get_attachment_url($id);
// Mimic functionality in image_downsize function in wp-includes/media.php
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
} elseif ($size == 'thumbnail') {
// fall back to the old thumbnail
if ($thumb_file = wp_get_attachment_thumb_file() && ($info = getimagesize($thumb_file))) {
$img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
}
}
if ($img_url) {
return array($img_url, 0, 0);
}
return FALSE;
}
示例4: wp_get_attachment_thumb_url
/**
* Retrieve URL for an attachment thumbnail.
*
* @since 2.1.0
*
* @param int $post_id Attachment ID
* @return string|bool False on failure. Thumbnail URL on success.
*/
function wp_get_attachment_thumb_url($post_id = 0)
{
$post_id = (int) $post_id;
if (!($post =& get_post($post_id))) {
return false;
}
if (!($url = wp_get_attachment_url($post->ID))) {
return false;
}
$sized = image_downsize($post_id, 'thumbnail');
if ($sized) {
return $sized[0];
}
if (!($thumb = wp_get_attachment_thumb_file($post->ID))) {
return false;
}
$url = str_replace(basename($url), basename($thumb), $url);
return apply_filters('wp_get_attachment_thumb_url', $url, $post->ID);
}
示例5: wp_get_attachment_thumb_url
/**
* Retrieve URL for an attachment thumbnail.
*
* @since 2.1.0
*
* @param int $post_id Optional. Attachment ID. Default 0.
* @return string|false False on failure. Thumbnail URL on success.
*/
function wp_get_attachment_thumb_url($post_id = 0)
{
$post_id = (int) $post_id;
if (!($post = get_post($post_id))) {
return false;
}
if (!($url = wp_get_attachment_url($post->ID))) {
return false;
}
$sized = image_downsize($post_id, 'thumbnail');
if ($sized) {
return $sized[0];
}
if (!($thumb = wp_get_attachment_thumb_file($post->ID))) {
return false;
}
$url = str_replace(basename($url), basename($thumb), $url);
/**
* Filter the attachment thumbnail URL.
*
* @since 2.1.0
*
* @param string $url URL for the attachment thumbnail.
* @param int $post_id Attachment ID.
*/
return apply_filters('wp_get_attachment_thumb_url', $url, $post->ID);
}
示例6: image_downsize
/**
* Scale an image to fit a particular size (such as 'thumb' or 'medium').
*
* Array with image url, width, height, and whether is intermediate size, in
* that order is returned on success is returned. $is_intermediate is true if
* $url is a resized image, false if it is the original.
*
* The URL might be the original image, or it might be a resized version. This
* function won't create a new resized copy, it will just return an already
* resized one if it exists.
*
* A plugin may use the 'image_downsize' filter to hook into and offer image
* resizing services for images. The hook must return an array with the same
* elements that are returned in the function. The first element being the URL
* to the new image that was resized.
*
* @since 2.5.0
*
* @param int $id Attachment ID for image.
* @param array|string $size Optional. Image size to scale to. Accepts any valid image size,
* or an array of width and height values in pixels (in that order).
* Default 'medium'.
* @return false|array Array containing the image URL, width, height, and boolean for whether
* the image is an intermediate size. False on failure.
*/
function image_downsize($id, $size = 'medium')
{
if (!wp_attachment_is_image($id)) {
return false;
}
/**
* Filter whether to preempt the output of image_downsize().
*
* Passing a truthy value to the filter will effectively short-circuit
* down-sizing the image, returning that value as output instead.
*
* @since 2.5.0
*
* @param bool $downsize Whether to short-circuit the image downsize. Default false.
* @param int $id Attachment ID for image.
* @param array|string $size Size of image. Image size or array of width and height values (in that order).
* Default 'medium'.
*/
if ($out = apply_filters('image_downsize', false, $id, $size)) {
return $out;
}
$img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
$width = $height = 0;
$is_intermediate = false;
$img_url_basename = wp_basename($img_url);
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
$width = $intermediate['width'];
$height = $intermediate['height'];
$is_intermediate = true;
} elseif ($size == 'thumbnail') {
// fall back to the old thumbnail
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
$width = $info[0];
$height = $info[1];
$is_intermediate = true;
}
}
if (!$width && !$height && isset($meta['width'], $meta['height'])) {
// any other type: use the real image
$width = $meta['width'];
$height = $meta['height'];
}
if ($img_url) {
// we have the actual image size, but might need to further constrain it if content_width is narrower
list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
return array($img_url, $width, $height, $is_intermediate);
}
return false;
}
示例7: convert_get_attachment_to_cloudinary_pull_request
/**
* Filter all thumbnails and image attachments typically used in template parts, archive loops, and widgets
*/
static function convert_get_attachment_to_cloudinary_pull_request($override, $id, $size)
{
$account = static::get_option_value('cloud_name');
//if no account is set, do not continue
if (empty($account)) {
return false;
}
//prepare values for string replacements
$img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
$width = $height = 0;
$is_intermediate = false;
$img_url_basename = wp_basename($img_url);
$cdn_fetch_prefix = static::get_cdn_prefix($account);
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$width = $intermediate['width'];
$height = $intermediate['height'];
$original = image_get_intermediate_size($id, 'full');
$is_intermediate = true;
} elseif ($size == 'thumbnail') {
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$width = $info[0];
$height = $info[1];
$is_intermediate = true;
}
}
//make sure we have height and width values
if (!$width && !$height && isset($meta['width'], $meta['height'])) {
// any other type: use the real image
$width = $meta['width'];
$height = $meta['height'];
}
//if image found then modify it with cloudinary optimimized replacement
if ($img_url) {
$site_url = get_bloginfo('url');
// get_bloginfo( 'url' ) is called a few time, it should be move to a property of this class, i.e. $this->blogurl, or something
$site_url_no_protocal = preg_replace('/http[s]?:\\/\\//', '', $site_url);
// we have the actual image size, but might need to further constrain it if content_width is narrower
list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
$cdn_fetch_options = static::get_cdn_options($height, $width);
//strip protocal from image URL
$cdn_img_url = preg_replace('/(http:|https:)?\\/\\/(.*)/i', '$1' . $cdn_fetch_prefix . $cdn_fetch_options . "/\$2", $img_url);
// do you need the double quotes on /$2 here or would single quotes work?
return array($cdn_img_url, $width, $height, $is_intermediate);
}
//if for some reason $img_url fails, disable filter by returning false
return false;
}
开发者ID:WordPress-Phoenix,项目名称:wordpress-cloudinary-config-free-cdn-images,代码行数:52,代码来源:sm-cloudinary-config-free-cdn-images.php
示例8: wp_get_attachment_thumb_url
function wp_get_attachment_thumb_url( $post_id = 0 ) {
$post_id = (int) $post_id;
if ( !$post =& get_post( $post_id ) )
return false;
if ( !$url = wp_get_attachment_url( $post->ID ) )
return false;
if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
return false;
$url = str_replace(basename($url), basename($thumb), $url);
return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
}
示例9: get_attachment_icon_src
function get_attachment_icon_src( $id = 0, $fullsize = false ) {
$id = (int) $id;
if ( !$post = & get_post($id) )
return false;
$imagedata = wp_get_attachment_metadata( $post->ID );
$file = get_attached_file( $post->ID );
if ( !$fullsize && $thumbfile = wp_get_attachment_thumb_file( $post->ID ) ) {
// We have a thumbnail desired, specified and existing
$src = wp_get_attachment_thumb_url( $post->ID );
$src_file = $thumbfile;
$class = 'attachmentthumb';
} elseif ( wp_attachment_is_image( $post->ID ) ) {
// We have an image without a thumbnail
$src = wp_get_attachment_url( $post->ID );
$src_file = & $file;
$class = 'attachmentimage';
} elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
// No thumb, no image. We'll look for a mime-related icon instead.
$icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
$src_file = $icon_dir . '/' . basename($src);
}
if ( !isset($src) || !$src )
return false;
return array($src, $src_file);
}
示例10: h2only_image_downsize
function h2only_image_downsize($value = false, $id, $size)
{
if (!wp_attachment_is_image($id)) {
return false;
}
$img_url = wp_get_attachment_url($id);
$is_intermediate = false;
$img_url_basename = wp_basename($img_url);
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
$is_intermediate = true;
} elseif ($size == 'thumbnail') {
// Fall back to the old thumbnail
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
$is_intermediate = true;
}
}
// We have the actual image size, but might need to further constrain it if content_width is narrower
if ($img_url) {
return array($img_url, 0, 0, $is_intermediate);
}
return false;
}
示例11: thumb
/**
* Get a thumbnail for an attachment, allowing us to override wp_options.
*
* @param int $id ID of attachment
* @param int $max_w Maximum width (wp_option setting by default)
* @param int $max_h Maximum height (wp_option setting by default)
* @param bool $crop Should we crop rather than scale? (wp_option setting by default)
* @return string URL of thumbnail, or false
*/
function thumb($id, $max_w = null, $max_h = null, $crop = null)
{
if ($max_w === null) {
$max_w = get_option('thumbnail_size_w');
}
if ($max_h === null) {
$max_h = get_option('thumbnail_size_h');
}
if ($crop === null) {
$crop = get_option('thumbnail_crop');
}
return str_replace(basename(wp_get_attachment_thumb_url($id)), basename(image_resize(wp_get_attachment_thumb_file($id), $max_w, $max_h, $crop)), wp_get_attachment_thumb_url($id));
}
示例12: hello_img
function hello_img($value, $id, $size = 'medium')
{
$img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
$width = $height = 0;
$is_intermediate = false;
$img_url_basename = wp_basename($img_url);
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
$width = $intermediate['width'];
$height = $intermediate['height'];
$is_intermediate = true;
} elseif ($size == 'thumbnail') {
// fall back to the old thumbnail
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
$width = $info[0];
$height = $info[1];
$is_intermediate = true;
}
}
if (!$width && !$height && isset($meta['width'], $meta['height'])) {
// any other type: use the real image
$width = $meta['width'];
$height = $meta['height'];
}
if ($img_url) {
$header_response = get_headers($img_url, 1);
if (strpos($header_response[0], "404") == false) {
// we have the actual image size, but might need to further constrain it if content_width is narrower
list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
return array($img_url, $width, $height, $is_intermediate);
} else {
$html = get_template_directory_uri() . '/assets/img/placeholder/' . $size . '.png';
return array($html, $width, $height, $is_intermediate);
}
}
return false;
}