本文整理汇总了PHP中image_downsize函数的典型用法代码示例。如果您正苦于以下问题:PHP image_downsize函数的具体用法?PHP image_downsize怎么用?PHP image_downsize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了image_downsize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: social_ring_get_first_image
function social_ring_get_first_image()
{
global $post, $posts;
if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'post-thumbnail');
if ($thumbnail) {
$image = $thumbnail[0];
}
// If that's not there, grab the first attached image
} else {
$files = get_children(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
if ($files) {
$keys = array_reverse(array_keys($files));
$image = image_downsize($keys[0], 'thumbnail');
$image = $image[0];
}
}
//if there's no attached image, try to grab first image in content
if (empty($image)) {
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if (!empty($matches[1][0])) {
$image = $matches[1][0];
}
}
return $image;
}
示例2: eme_ical_single_event
function eme_ical_single_event($event, $title_format, $description_format) {
global $eme_timezone;
$title = eme_sanitize_ical (eme_replace_placeholders ( $title_format, $event, "text" ));
$description = eme_sanitize_ical (eme_replace_placeholders ( $description_format, $event, "text" ));
$html_description = eme_sanitize_ical (eme_replace_placeholders ( $description_format, $event, "html" ),1);
$event_link = eme_event_url($event);
$startstring=new ExpressiveDate($event['event_start_date']." ".$event['event_start_time'],$eme_timezone);
$dtstartdate=$startstring->format("Ymd");
$dtstarthour=$startstring->format("His");
//$dtstart=$dtstartdate."T".$dtstarthour."Z";
// we'll use localtime, so no "Z"
$dtstart=$dtstartdate."T".$dtstarthour;
if ($event['event_end_date'] == "")
$event['event_end_date'] = $event['event_start_date'];
if ($event['event_end_time'] == "")
$event['event_end_time'] = $event['event_start_time'];
$endstring=$event['event_end_date']." ".$event['event_end_time'];
$endstring=new ExpressiveDate($event['event_end_date']." ".$event['event_end_time'],$eme_timezone);
$dtenddate=$endstring->format("Ymd");
$dtendhour=$endstring->format("His");
//$dtend=$dtenddate."T".$dtendhour."Z";
// we'll use localtime, so no "Z"
$dtend=$dtenddate."T".$dtendhour;
$tzstring = get_option('timezone_string');
$res = "";
$res .= "BEGIN:VEVENT\r\n";
//DTSTAMP must be in UTC format, so adding "Z" as well
$res .= "DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\r\n";
if ($event['event_properties']['all_day']) {
// ical standard for an all day event: specify only the day, meaning
// an 'all day' event is flagged as starting at the beginning of one day and lasting until the beginning of the next
// so it is the same as adding "T000000" as time spec to the start/end datestring
// But since it "ends" at the beginning of the next day, we should add 24 hours, otherwise the event ends one day too soon
$dtenddate=$endstring->addOneDay()->format('Ymd');
$res .= "DTSTART;VALUE=DATE:$dtstartdate\r\n";
$res .= "DTEND;VALUE=DATE:$dtenddate\r\n";
} else {
$res .= "DTSTART;TZID=$tzstring:$dtstart\r\n";
$res .= "DTEND;TZID=$tzstring:$dtend\r\n";
}
$res .= "UID:$dtstart-$dtend-".$event['event_id']."@".$_SERVER['SERVER_NAME']."\r\n";
$res .= "SUMMARY:$title\r\n";
$res .= "DESCRIPTION:$description\r\n";
$res .= "X-ALT-DESC;FMTTYPE=text/html:$html_description\r\n";
$res .= "URL:$event_link\r\n";
$res .= "ATTACH:$event_link\r\n";
if ($event['event_image_id']) {
$thumb_array = image_downsize( $event['event_image_id'], get_option('eme_thumbnail_size') );
$thumb_url = $thumb_array[0];
$res .= "ATTACH:$thumb_url\r\n";
}
if (isset($event['location_id']) && $event['location_id']) {
$location = eme_sanitize_ical (eme_replace_placeholders ( "#_LOCATION, #_ADDRESS, #_TOWN", $event, "text" ));
$res .= "LOCATION:$location\r\n";
}
$res .= "END:VEVENT\r\n";
return $res;
}
示例3: circleflip_make_missing_intermediate_size
/** generate new image sizes for old uploads
*
* @param mixed $out
* @param int $id
* @param string|array $size
* @return mixed
*/
function circleflip_make_missing_intermediate_size($out, $id, $size)
{
$skip_sizes = array('full', 'large', 'medium', 'thumbnail', 'thumb');
if (is_array($size) || in_array($size, $skip_sizes)) {
return $out;
}
// the size exists and the attachment doesn't have a pre-generated file of that size
// or the intermediate size defintion changed ( during development )
if (circleflip_intermediate_size_exists($size) && (!circleflip_image_has_intermediate_size($id, $size) || circleflip_has_intermediate_size_changed($id, $size))) {
// get info registerd by add_image_size
$size_info = circleflip_get_intermediate_size_info($size);
// get path to the original file
$file_path = get_attached_file($id);
// resize the image
$resized_file = image_make_intermediate_size($file_path, $size_info['width'], $size_info['height'], $size_info['crop']);
if ($resized_file) {
// we have a resized image, get the attachment metadata and add the new size to it
$metadata = wp_get_attachment_metadata($id);
$metadata['sizes'][$size] = $resized_file;
if (wp_update_attachment_metadata($id, $metadata)) {
// update succeded, call image_downsize again , DRY
return image_downsize($id, $size);
}
} else {
// failed to generate the resized image
// call image_downsize with `full` to prevent infinit loop
return image_downsize($id, 'full');
}
}
// pre-existing intermediate size
return $out;
}
示例4: getImageThumbnail
/**
* @param string $ID The attachment ID to retrieve thumbnail from.
*
* @return bool|string False on failure, URL to thumb on success.
*/
private static function getImageThumbnail($ID)
{
$options = DG_Thumber::getOptions();
$ret = false;
if ($icon = image_downsize($ID, array($options['width'], $options['height']))) {
$ret = $icon[0];
}
return $ret;
}
示例5: the_thumb
function the_thumb($size = "medium", $add = "")
{
global $wpdb, $post;
$thumb = $wpdb->get_row("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_parent = {$post->ID} AND post_mime_type LIKE 'image%' ORDER BY menu_order");
if (!empty($thumb)) {
$image = image_downsize($thumb->ID, $size);
print "<img src='{$image[0]}' alt='{$thumb->post_title}' {$add} />";
}
}
示例6: theme_gallery_lightbox
/**
* Post gGallery with lightbox ready for use.
*/
function theme_gallery_lightbox($post_id)
{
global $post;
$thumbnail_ID = get_post_thumbnail_id();
$images = get_children(array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
if ($images) {
?>
<ul class="gallery-list" data-action="gallery-<?php
the_ID();
?>
" data-ui-component="gallery">
<?php
foreach ($images as $attachment_id => $image) {
if ($image->ID != $thumbnail_ID) {
$img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
//alt
if ($img_alt == '') {
$img_alt = $img_title;
}
$big_array = image_downsize($image->ID, 'full');
$img_url = $big_array[0];
?>
<li class="gallery-item" data-src="<?php
echo $image_url;
?>
" data-html="<div class='gallery-caption'><h4 class='text-inverse'><?php
echo the_title();
?>
</h4><?php
echo the_content();
?>
</div>">
<img src="<?php
echo $img_url;
?>
" alt="<?php
echo $img_alt;
?>
" title="<?php
echo $img_title;
?>
" />
</li>
<?php
}
?>
<?php
}
?>
</ul>
<?php
}
}
示例7: tevkori_get_sizes
/**
* Return a source size attribute for an image from an array of values.
*
* @since 2.2.0
*
* @param int $id Image attachment ID.
* @param string $size Optional. Name of image size. Default value: 'medium'.
* @param array $args {
* Optional. Arguments to retrieve posts.
*
* @type array|string $sizes An array or string containing of size information.
* @type int $width A single width value used in the default `sizes` string.
* }
* @return string|bool A valid source size value for use in a 'sizes' attribute or false.
*/
function tevkori_get_sizes($id, $size = 'medium', $args = null)
{
// Try to get the image width from `$args` before calling `image_downsize()`.
if (is_array($args) && !empty($args['width'])) {
$img_width = (int) $args['width'];
} elseif ($img = image_downsize($id, $size)) {
$img_width = $img[1];
}
// Bail early if ``$image_width` isn't set.
if (!$img_width) {
return false;
}
// Set the image width in pixels.
$img_width = $img_width . 'px';
// Set up our default values.
$defaults = array('sizes' => array(array('size_value' => '100vw', 'mq_value' => $img_width, 'mq_name' => 'max-width'), array('size_value' => $img_width)));
$args = wp_parse_args($args, $defaults);
/**
* Filter arguments used to create 'sizes' attribute.
*
* @since 2.4.0
*
* @param array $args An array of arguments used to create a 'sizes' attribute.
* @param int $id Post ID of the original image.
* @param string $size Name of the image size being used.
*/
$args = apply_filters('tevkori_image_sizes_args', $args, $id, $size);
// If sizes is passed as a string, just use the string.
if (is_string($args['sizes'])) {
$size_list = $args['sizes'];
// Otherwise, breakdown the array and build a sizes string.
} elseif (is_array($args['sizes'])) {
$size_list = '';
foreach ($args['sizes'] as $size) {
// Use 100vw as the size value unless something else is specified.
$size_value = $size['size_value'] ? $size['size_value'] : '100vw';
// If a media length is specified, build the media query.
if (!empty($size['mq_value'])) {
$media_length = $size['mq_value'];
// Use max-width as the media condition unless min-width is specified.
$media_condition = !empty($size['mq_name']) ? $size['mq_name'] : 'max-width';
// If a media_length was set, create the media query.
$media_query = '(' . $media_condition . ": " . $media_length . ') ';
} else {
// If not meda length was set, $media_query is blank.
$media_query = '';
}
// Add to the source size list string.
$size_list .= $media_query . $size_value . ', ';
}
// Remove the trailing comma and space from the end of the string.
$size_list = substr($size_list, 0, -2);
}
// If $size_list is defined set the string, otherwise set false.
return $size_list ? $size_list : false;
}
示例8: eazy_css_slider_image_size
function eazy_css_slider_image_size($downsize, $id, $size)
{
if (!is_admin() || !get_current_screen() || 'edit' !== get_current_screen()->parent_base) {
return $downsize;
}
remove_filter('image_downsize', __FUNCTION__, 10, 3);
// settings can be thumbnail, medium, large, full
$image = image_downsize($id, 'medium');
add_filter('image_downsize', __FUNCTION__, 10, 3);
return $image;
}
示例9: nerdy_get_images
function nerdy_get_images($size = 'thumbnail', $limit = '0', $offset = '0')
{
global $post;
$images = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
if ($images) {
$num_of_images = count($images);
if ($offset > 0) {
$start = $offset--;
} else {
$start = 0;
}
if ($limit > 0) {
$stop = $limit + $start;
} else {
$stop = $num_of_images;
}
$i = 0;
foreach ($images as $image) {
if ($start <= $i and $i < $stop) {
$img_title = $image->post_title;
// title.
$img_description = $image->post_content;
// description.
$img_caption = $image->post_excerpt;
// caption.
$img_url = wp_get_attachment_url($image->ID);
// url of the full size image.
$preview_array = image_downsize($image->ID, $size);
$img_preview = $preview_array[0];
// thumbnail or medium image to use for preview.
?>
<li>
<a href="<?php
echo $img_url;
?>
"><img src="<?php
echo $img_preview;
?>
" alt="<?php
echo $img_caption;
?>
" title="<?php
echo $img_title;
?>
"></a>
</li>
<?php
}
$i++;
}
}
}
示例10: getImageTag
function getImageTag($id, $alt, $title, $align, $size = 'medium', $attrs = array())
{
list($img_src, $width, $height) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);
$class = 'align' . esc_attr($align) . ' size-' . esc_attr($size) . ' wp-image-' . $id;
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
$attrs_fields = '';
foreach ($attrs as $name => $attr) {
$attrs_fields .= ' ' . $name . '="' . esc_attr($attr) . '" ';
}
$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title) . '" ' . $hwstring . 'class="' . $class . '" ' . $attrs_fields . ' />';
return $html;
}
示例11: getImageSquareSize
public function getImageSquareSize($img_id, $img_size)
{
if (preg_match_all('/(\\d+)x(\\d+)/', $img_size, $sizes)) {
$exact_size = array('width' => isset($sizes[1][0]) ? $sizes[1][0] : '0', 'height' => isset($sizes[2][0]) ? $sizes[2][0] : '0');
} else {
$image_downsize = image_downsize($img_id, $img_size);
$exact_size = array('width' => $image_downsize[1], 'height' => $image_downsize[2]);
}
if (isset($exact_size['width']) && (int) $exact_size['width'] !== (int) $exact_size['height']) {
$img_size = (int) $exact_size['width'] > (int) $exact_size['height'] ? $exact_size['height'] . 'x' . $exact_size['height'] : $exact_size['width'] . 'x' . $exact_size['width'];
}
return $img_size;
}
示例12: get_audiotheme_playlist_track
/**
* Convert a track into the format expected by the Cue plugin.
*
* @since 1.5.0
*
* @param int|WP_Post $post Post object or ID.
* @return object Track object expected by Cue.
*/
function get_audiotheme_playlist_track($post = 0)
{
$post = get_post($post);
$track = new stdClass();
$track->id = $post->ID;
$track->artist = get_audiotheme_track_artist($post->ID);
$track->audioUrl = get_audiotheme_track_file_url($post->ID);
$track->title = get_the_title($post->ID);
if ($thumbnail_id = get_audiotheme_track_thumbnail_id($post->ID)) {
$size = apply_filters('cue_artwork_size', array(300, 300));
$image = image_downsize($thumbnail_id, $size);
$track->artworkUrl = $image[0];
}
return $track;
}
示例13: argo_get_image_tag
/**
* argo_get_image_tag(): Renders an <img /> tag for attachments, scaling it
* to $size and guaranteeing that it's not wider than the content well.
*
* This is largely taken from get_image_tag() in wp-includes/media.php.
*/
function argo_get_image_tag($html, $id, $alt, $title, $align, $size)
{
// Never allow an image wider than the LARGE_WIDTH
if ($size == 'full') {
list($img_src, $width, $height) = wp_get_attachment_image_src($id, $size);
if ($width > LARGE_WIDTH) {
$size = 'large';
}
}
list($img_src, $width, $height) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);
// XXX: may not need all these classes
$class = 'align' . esc_attr($align) . ' size-' . esc_attr($size) . ' wp-image-' . $id;
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title) . '" ' . $hwstring . 'class="' . $class . '" />';
return $html;
}
示例14: nerdy_project_slide_get_images
function nerdy_project_slide_get_images($size = 'thumbnail', $limit = '0', $offset = '0')
{
global $post;
$images = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
if ($images) {
$num_of_images = count($images);
if ($offset > 0) {
$start = $offset--;
} else {
$start = 0;
}
if ($limit > 0) {
$stop = $limit + $start;
} else {
$stop = $num_of_images;
}
$i = 0;
foreach ($images as $image) {
if ($start <= $i and $i < $stop) {
$img_title = $image->post_title;
// title.
$img_description = $image->post_content;
// description.
$img_caption = $image->post_excerpt;
// caption.
$img_url = wp_get_attachment_url($image->ID);
// url of the full size image.
$preview_array = image_downsize($image->ID, $size);
$img_preview = $preview_array[0];
// thumbnail or medium image to use for preview.
///////////////////////////////////////////////////////////
// This is where you'd create your custom image/link/whatever tag using the variables above.
// This is an example of a basic image tag using this method.
?>
<div><img src="<?php
echo $img_preview;
?>
" /></div>
<?php
// End custom image tag. Do not edit below here.
///////////////////////////////////////////////////////////
}
$i++;
}
}
}
示例15: get_src
function get_src($size = '')
{
if (isset($this->abs_url)) {
return $this->abs_url;
}
if ($size && is_string($size) && isset($this->sizes[$size])) {
$image = image_downsize($this->ID, $size);
return reset($image);
}
if (!isset($this->file) && isset($this->_wp_attached_file)) {
$this->file = $this->_wp_attached_file;
}
if (!isset($this->file)) {
return false;
}
$dir = wp_upload_dir();
$base = $dir["baseurl"];
return trailingslashit($base) . $this->file;
}