/** * 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 * @uses apply_filters() Calls 'image_downsize' on $id and $size to provide * resize services. * * @param int $id Attachment ID for image. * @param array|string $size Optional, default is 'medium'. Size of image, either array or string. * @return bool|array False on failure, array on success. */ function image_downsize($id, $size = 'medium') { if (!nxt_attachment_is_image($id)) { return false; } $img_url = nxt_get_attachment_url($id); $meta = nxt_get_attachment_metadata($id); $width = $height = 0; $is_intermediate = false; $img_url_basename = nxt_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 = nxt_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) { $img_url = str_replace($img_url_basename, nxt_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; }
?> <div class="entry-caption"><?php if (!empty($post->post_excerpt)) { the_excerpt(); } ?> </div> <?php the_content(); ?> </div> <p class="postmetadata"> <?php if (nxt_attachment_is_image()) { $metadata = nxt_get_attachment_metadata(); printf(__('Full size is %s pixels', 'buddypress'), sprintf('<a href="%1$s" title="%2$s">%3$s × %4$s</a>', nxt_get_attachment_url(), esc_attr(__('Link to full size image', 'buddypress')), $metadata['width'], $metadata['height'])); } ?> </p> </div> </div> <?php do_action('bp_after_blog_post'); ?> <?php
/** * Retrieve icon URL and Path. * * @since 2.1.0 * @deprecated 2.5.0 * @deprecated Use nxt_get_attachment_image_src() * @see nxt_get_attachment_image_src() * * @param int $id Optional. Post ID. * @param bool $fullsize Optional, default to false. Whether to have full image. * @return array Icon URL and full path to file, respectively. */ function get_attachment_icon_src($id = 0, $fullsize = false) { _deprecated_function(__FUNCTION__, '2.5', 'nxt_get_attachment_image_src()'); $id = (int) $id; if (!($post =& get_post($id))) { return false; } $file = get_attached_file($post->ID); if (!$fullsize && ($src = nxt_get_attachment_thumb_url($post->ID))) { // We have a thumbnail desired, specified and existing $src_file = basename($src); $class = 'attachmentthumb'; } elseif (nxt_attachment_is_image($post->ID)) { // We have an image without a thumbnail $src = nxt_get_attachment_url($post->ID); $src_file =& $file; $class = 'attachmentimage'; } elseif ($src = nxt_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); }