image_downsize [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
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.
Source
<?php
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;
$is_intermediate = false;
$img_url_basename = wp_basename($img_url);
// 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($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;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/image downsize « WordPress Codex
Description. Scale an image to fit a particular size (such as 'thumb' or 'medium' ). The $max_/$min_width for the Reserved Names will always be what you ...
codex.wordpress.org - WordPress › Support » Tags — image_downsize
Username or Email Address Password (forgot?) Register · WordPress › Support » image_downsize. Tag: image_downsize Add New » · Developer Information ...
wordpress.org - image_downsize returning an Array? - WordPress - Stack Exchange
Feb 14, 2012 ... I'm attempting to generate a thumbnail for an image I have posted, but it seems when I call image_downsize, the index[0] actually prints an ...
wordpress.stackexchange.com - image_downsize Wordpress hook details -- Adam Brown, BYU ...
Detailed information about every action hook and filter used in WordPress. Makes Plugin API easier to use. Lists appearance, file location, and deprecation data ...
adambrown.info
Gebruikersdiscussies [ wordpress.org ]
- ssonmez on "two upload image errors (2.5)"
- shogunn on "two upload image errors (2.5)"
- shogunn on "two upload image errors (2.5)"
- shogunn on "two upload image errors (2.5)"
- ilyushkin on "two upload image errors (2.5)"
- jamble on "two upload image errors (2.5)"
- jaynee on "two upload image errors (2.5)"
- JBF on "two upload image errors (2.5)"
- Mitheor on "two upload image errors (2.5)"
- Bjooti on "two upload image errors (2.5)"