本文整理汇总了PHP中get_intermediate_image_sizes函数的典型用法代码示例。如果您正苦于以下问题:PHP get_intermediate_image_sizes函数的具体用法?PHP get_intermediate_image_sizes怎么用?PHP get_intermediate_image_sizes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_intermediate_image_sizes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_image_sizes
function get_image_sizes($size = '')
{
global $_wp_additional_image_sizes;
$sizes = array();
$get_intermediate_image_sizes = get_intermediate_image_sizes();
// Create the full array with sizes and crop info
foreach ($get_intermediate_image_sizes as $_size) {
if (in_array($_size, array('thumbnail', 'medium', 'large'))) {
$sizes[$_size]['width'] = get_option($_size . '_size_w');
$sizes[$_size]['height'] = get_option($_size . '_size_h');
$sizes[$_size]['crop'] = (bool) get_option($_size . '_crop');
} elseif (isset($_wp_additional_image_sizes[$_size])) {
$sizes[$_size] = array('width' => $_wp_additional_image_sizes[$_size]['width'], 'height' => $_wp_additional_image_sizes[$_size]['height'], 'crop' => $_wp_additional_image_sizes[$_size]['crop']);
}
}
// Get only 1 size if found
if ($size) {
if (isset($sizes[$size])) {
return $sizes[$size];
} else {
return false;
}
}
return $sizes;
}
示例2: groundup_image_suffix
function groundup_image_suffix($image)
{
// Split the $image path into directory/extension/name
$info = pathinfo($image);
$dir = $info['dirname'] . '/';
$ext = '.' . $info['extension'];
$file_name = wp_basename($image, "{$ext}");
$image_name = substr($file_name, 0, strrpos($file_name, '-'));
// Get image information
$img = wp_get_image_editor($image);
// Get image size, width and height
$img_size = $img->get_size();
// Get new image suffix by comparing image sizes
$image_sizes = get_intermediate_image_sizes();
foreach ($image_sizes as $size) {
$rename = false;
$sizeInfo = get_image_size_data($size);
if ($img_size['width'] == $sizeInfo['width'] && $img_size['height'] <= $sizeInfo['height']) {
$rename = true;
} elseif ($img_size['height'] == $sizeInfo['height'] && $img_size['width'] <= $sizeInfo['width']) {
$rename = true;
}
if ($rename == true) {
// Rename image
$new_name = $dir . $image_name . '-' . $size . $ext;
// Rename the intermediate size
$rename_success = rename($image, $new_name);
if ($rename_success) {
return $new_name;
}
}
}
// do nothing if not renamed
return $image;
}
示例3: check_size_exist
function check_size_exist($size)
{
$registeredSized = get_intermediate_image_sizes();
if (!in_array($size, $registeredSized)) {
throw new Exception("This image size is not registered in wordpress");
}
}
示例4: get_html
public function get_html($media_id, $sizes = null, array $attrs = array(), $square = false, $def_wp_size = null, $use_fallback = false)
{
if (empty($def_wp_size)) {
$def_wp_size = $square ? 'thumbnail' : 'medium';
}
$img_src = wp_get_attachment_image_url($media_id, $def_wp_size);
if (empty($img_src)) {
$result = $use_fallback ? call_user_func_array(array($this, 'get_html_fallback'), func_get_args()) : false;
return $result;
}
$img_srcset = wp_get_attachment_image_srcset($media_id, $def_wp_size);
$img_data = array();
foreach (get_intermediate_image_sizes() as $size) {
$img_data[$size] = wp_get_attachment_image_src($media_id, $size);
}
$img_data = $this->filter_square($img_data, $square);
if (!empty($this->filter_srcset)) {
foreach ($this->filter_srcset as $filter) {
$img_srcset = call_user_func($filter, $img_data, $media_id, $size, $attrs, $square, $def_wp_size);
}
}
$attrs = array_merge(array('src' => $img_src, 'srcset' => $img_srcset, 'sizes' => $this->get_sizes($sizes)), $attrs);
if (empty($attrs['srcset'])) {
unset($attrs['srcset']);
unset($attrs['sizes']);
}
$result = \Cibulka::Base('HTML', 'img', $attrs, true);
return $result;
}
示例5: pte_site_options_validate
function pte_site_options_validate($input)
{
//$sizes = pte_get_alternate_sizes(false);
if (!current_user_can('manage_options')) {
add_settings_error('pte_options_site', 'pte_options_error', __("Only users with the 'manage_options' capability may make changes to these settings.", PTE_DOMAIN));
return pte_get_site_options();
}
$sizes = get_intermediate_image_sizes();
$pte_hidden_sizes = array();
foreach ($sizes as $size) {
// Hidden
if (is_array($input['pte_hidden_sizes']) and in_array($size, $input['pte_hidden_sizes'])) {
$pte_hidden_sizes[] = $size;
}
}
$output = array('pte_hidden_sizes' => $pte_hidden_sizes);
// Check the JPEG Compression value
if ($input['pte_jpeg_compression'] != "") {
$tmp_jpeg_compression = (int) preg_replace("/[\\D]/", "", $input['pte_jpeg_compression']);
if (!is_int($tmp_jpeg_compression) || $tmp_jpeg_compression < 0 || $tmp_jpeg_compression > 100) {
add_settings_error('pte_options_site', 'pte_options_error', __("JPEG Compression needs to be set from 0 to 100.", PTE_DOMAIN) . $tmp_jpeg_compression . "/" . $input['pte_jpeg_compression']);
}
$output['pte_jpeg_compression'] = $tmp_jpeg_compression;
}
// Cache Buster
$output['cache_buster'] = isset($input['pte_cache_buster']);
return $output;
}
示例6: getImage
public function getImage($id)
{
$image_fields = array("ID" => "ID", "guid" => "file", "post_mime_type" => "mime_type");
$indexable_image_size = get_intermediate_image_sizes();
$uploadDir = wp_upload_dir();
$uploadBaseUrl = $uploadDir['baseurl'];
$image = new \stdClass();
$post = get_post($id);
foreach ($image_fields as $key => $value) {
$image->{$value} = $post->{$key};
}
$metas = get_post_meta($post->ID, '_wp_attachment_metadata', true);
$image->width = $metas["width"];
$image->height = $metas["height"];
$image->file = sprintf('%s/%s', $uploadBaseUrl, $metas["file"]);
$image->sizes = $metas["sizes"] ? $metas["sizes"] : array();
foreach ($image->sizes as $size => &$sizeAttrs) {
if (in_array($size, $indexable_image_size) == false) {
unset($image->sizes[$size]);
continue;
}
$baseFileUrl = str_replace(wp_basename($metas['file']), '', $metas['file']);
$sizeAttrs['file'] = sprintf('%s/%s%s', $uploadBaseUrl, $baseFileUrl, $sizeAttrs['file']);
}
return $image;
}
示例7: ilab_get_image_sizes
function ilab_get_image_sizes($size = null)
{
global $_wp_additional_image_sizes;
$sizes = [];
$get_intermediate_image_sizes = get_intermediate_image_sizes();
// Create the full array with sizes and crop info
foreach ($get_intermediate_image_sizes as $_size) {
if (in_array($_size, ['thumbnail', 'medium', 'large'])) {
$sizes[$_size]['width'] = get_option($_size . '_size_w');
$sizes[$_size]['height'] = get_option($_size . '_size_h');
$sizes[$_size]['crop'] = (bool) get_option($_size . '_crop');
} else {
if (isset($_wp_additional_image_sizes[$_size])) {
$sizes[$_size] = ['width' => $_wp_additional_image_sizes[$_size]['width'], 'height' => $_wp_additional_image_sizes[$_size]['height'], 'crop' => $_wp_additional_image_sizes[$_size]['crop']];
}
}
}
if ($size != null) {
if (isset($sizes[$size])) {
return $sizes[$size];
}
return null;
}
return $sizes;
}
示例8: simple_life_get_image_sizes_options
/**
* Returns image sizes options.
*
* @since 1.2
*
* @param bool $add_disable Add disable option or not.
* @param array $allowed Allowed array.
* @param bool $show_dimension Show or hide dimension.
*/
function simple_life_get_image_sizes_options($add_disable = true, $allowed = array(), $show_dimension = true)
{
global $_wp_additional_image_sizes;
$get_intermediate_image_sizes = get_intermediate_image_sizes();
$choices = array();
if (true === $add_disable) {
$choices['disable'] = esc_html__('No Image', 'simple-life');
}
$choices['thumbnail'] = esc_html__('Thumbnail', 'simple-life');
$choices['medium'] = esc_html__('Medium', 'simple-life');
$choices['large'] = esc_html__('Large', 'simple-life');
$choices['full'] = esc_html__('Full (original)', 'simple-life');
if (true === $show_dimension) {
foreach (array('thumbnail', 'medium', 'large') as $key => $_size) {
$choices[$_size] = $choices[$_size] . ' (' . get_option($_size . '_size_w') . 'x' . get_option($_size . '_size_h') . ')';
}
}
if (!empty($_wp_additional_image_sizes) && is_array($_wp_additional_image_sizes)) {
foreach ($_wp_additional_image_sizes as $key => $size) {
$choices[$key] = $key;
if (true === $show_dimension) {
$choices[$key] .= ' (' . $size['width'] . 'x' . $size['height'] . ')';
}
}
}
if (!empty($allowed)) {
foreach ($choices as $key => $value) {
if (!in_array($key, $allowed)) {
unset($choices[$key]);
}
}
}
return $choices;
}
示例9: get_value
function get_value($id)
{
$paths = array();
$meta = get_post_meta($id, '_wp_attachment_metadata', true);
if (!isset($meta['sizes'])) {
return $this->get_empty_char();
}
// available sizes
if ($intersect = array_intersect(array_keys($meta['sizes']), get_intermediate_image_sizes())) {
$url = wp_get_attachment_url($id);
$filename = basename($url);
$paths[] = "<a title='{$filename}' href='{$url}'>" . __('full size', 'codepress-admin-columns') . "</a>";
foreach ($intersect as $size) {
$src = wp_get_attachment_image_src($id, $size);
if (!empty($src[0])) {
$filename = basename($src[0]);
$paths[] = "<a title='{$filename}' href='{$src[0]}' class='available'>{$size}</a>";
}
}
}
global $_wp_additional_image_sizes;
if (!empty($_wp_additional_image_sizes)) {
if (isset($_wp_additional_image_sizes['post-thumbnail'])) {
unset($_wp_additional_image_sizes['post-thumbnail']);
}
// image does not have these additional sizes rendered yet
if ($missing = array_diff(array_keys($_wp_additional_image_sizes), array_keys($meta['sizes']))) {
foreach ($missing as $size) {
$paths[] = "<span title='Missing size: Try regenerate thumbnails with the plugin: Force Regenerate Thumbnails' href='javascript:;' class='not-available'>{$size}</span>";
}
}
}
return "<div class='sizes'>" . implode('<span class="cpac-divider"></span>', $paths) . "</div>";
}
示例10: add_placeholder_sizes
/**
* Loop through registered image sizes and add placeholders
*
* @global array $_wp_additional_image_sizes
*/
function add_placeholder_sizes()
{
global $_wp_additional_image_sizes;
if (!isset($_wp_additional_image_sizes)) {
$_wp_additional_image_sizes = array();
}
$new_sizes = array();
foreach (get_intermediate_image_sizes() as $name) {
if (isset($_wp_additional_image_sizes[$name]['width'])) {
$width = absint($_wp_additional_image_sizes[$name]['width']);
} else {
$width = absint(get_option("{$name}_size_w"));
}
if (isset($_wp_additional_image_sizes[$name]['height'])) {
$height = absint($_wp_additional_image_sizes[$name]['height']);
} else {
$height = absint(get_option("{$name}_size_h"));
}
if (isset($_wp_additional_image_sizes[$name]['crop'])) {
$crop = $_wp_additional_image_sizes[$name]['crop'];
} else {
$crop = get_option("{$name}_crop");
}
$new_sizes[$name . '-ph'] = array('width' => $width, 'height' => $height, 'crop' => $crop);
}
$_wp_additional_image_sizes = array_merge($_wp_additional_image_sizes, $new_sizes);
}
示例11: get_attachment_image_html
/**
* @param array $settings [ image => [ id => '', url => '' ], image_size => '', hover_animation => '' ]
*
* @return string
*/
public static function get_attachment_image_html($settings)
{
$id = $settings['image']['id'];
$url = $settings['image']['url'];
// Old version of image settings
if (!isset($settings['image_size'])) {
$settings['image_size'] = '';
}
$size = $settings['image_size'];
$image_class = !empty($settings['hover_animation']) ? 'elementor-animation-' . $settings['hover_animation'] : '';
$html = '';
// If is the new version - with image size
$image_sizes = get_intermediate_image_sizes();
$image_sizes[] = 'full';
if (!empty($id) && in_array($size, $image_sizes)) {
$image_class .= " attachment-{$size} size-{$size}";
$html .= wp_get_attachment_image($id, $size, false, ['class' => trim($image_class)]);
} else {
$image_src = Group_Control_Image_Size::get_attachment_image_src($id, 'image', $settings);
if (!$image_src) {
$image_src = $url;
}
$image_class_html = !empty($image_class) ? ' class="' . $image_class . '"' : '';
$html .= sprintf('<img src="%s" title="%s" alt="%s"%s />', esc_attr($image_src), Control_Media::get_image_title($settings['image']), Control_Media::get_image_alt($settings['image']), $image_class_html);
}
return $html;
}
示例12: sri_get_image_sizes
function sri_get_image_sizes($prefix = 'src-')
{
global $_wp_additional_image_sizes;
$other_sizes = array();
foreach (get_intermediate_image_sizes() as $s) {
if (isset($_wp_additional_image_sizes[$s]['width'])) {
// For theme-added sizes
$width = intval($_wp_additional_image_sizes[$s]['width']);
} else {
// For default sizes set in options
$width = get_option("{$s}_size_w");
}
// Set height
if (isset($_wp_additional_image_sizes[$s]['height'])) {
// For theme-added sizes
$height = intval($_wp_additional_image_sizes[$s]['height']);
} else {
// For default sizes set in options
$height = get_option("{$s}_size_h");
}
$other_sizes[] = array($prefix . $s, $width, $height);
}
$other_sizes[] = array($prefix . "full", 'max', 'max');
return $other_sizes;
}
示例13: hoot_get_image_size_links
/**
* Returns a set of image attachment links based on size.
*
* @since 1.0.0
* @access public
* @return string
*/
function hoot_get_image_size_links()
{
/* If not viewing an image attachment page, return. */
if (!wp_attachment_is_image(get_the_ID())) {
return;
}
/* Set up an empty array for the links. */
$links = array();
/* Get the intermediate image sizes and add the full size to the array. */
$sizes = get_intermediate_image_sizes();
$sizes[] = 'full';
/* Loop through each of the image sizes. */
foreach ($sizes as $size) {
/* Get the image source, width, height, and whether it's intermediate. */
$image = wp_get_attachment_image_src(get_the_ID(), $size);
/* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
if (!empty($image) && (true === $image[3] || 'full' == $size)) {
/* Translators: Media dimensions - 1 is width and 2 is height. */
$label = sprintf(__('%1$s × %2$s', 'chromatic'), number_format_i18n(absint($image[1])), number_format_i18n(absint($image[2])));
$links[] = sprintf('<a class="image-size-link">%s</a>', $label);
}
}
/* Join the links in a string and return. */
return join(' <span class="sep">/</span> ', $links);
}
示例14: kt_get_image_sizes
/**
* Get image sizes
*
* @return array
*/
function kt_get_image_sizes($full = true, $custom = false)
{
global $_wp_additional_image_sizes;
$get_intermediate_image_sizes = get_intermediate_image_sizes();
$sizes = array();
// Create the full array with sizes and crop info
foreach ($get_intermediate_image_sizes as $_size) {
if (in_array($_size, array('thumbnail', 'medium', 'large'))) {
$sizes[$_size]['width'] = get_option($_size . '_size_w');
$sizes[$_size]['height'] = get_option($_size . '_size_h');
$sizes[$_size]['crop'] = (bool) get_option($_size . '_crop');
} elseif (isset($_wp_additional_image_sizes[$_size])) {
$sizes[$_size] = array('width' => $_wp_additional_image_sizes[$_size]['width'], 'height' => $_wp_additional_image_sizes[$_size]['height'], 'crop' => $_wp_additional_image_sizes[$_size]['crop']);
}
$option_text = array();
$option_text[] = ucfirst(str_replace('_', ' ', $_size));
if (isset($sizes[$_size])) {
$option_text[] = '(' . $sizes[$_size]['width'] . ' x ' . $sizes[$_size]['height'] . ')';
if ($sizes[$_size]['crop']) {
$option_text[] = esc_html__('Crop', 'adroit');
}
$sizes[$_size] = implode(' - ', $option_text);
}
}
if ($full) {
$sizes['full'] = esc_html__('Full', 'adroit');
}
if ($custom) {
$sizes['custom'] = esc_html__('Custom size', 'adroit');
}
return $sizes;
}
示例15: gdlr_get_video_size
function gdlr_get_video_size($size)
{
global $_wp_additional_image_sizes, $theme_option, $gdlr_crop_video;
// get video ratio
if (!empty($theme_option['video-ratio']) && preg_match('#^(\\d+)[\\/:](\\d+)$#', $theme_option['video-ratio'], $number)) {
$ratio = $number[1] / $number[2];
} else {
$ratio = 16 / 9;
}
// get video size
$video_size = array('width' => 620, 'height' => 9999);
if (!empty($size) && is_numeric($size)) {
$video_size['width'] = intval($size);
} else {
if (!empty($size) && !empty($_wp_additional_image_sizes[$size])) {
$video_size = $_wp_additional_image_sizes[$size];
} else {
if (!empty($size) && in_array($size, get_intermediate_image_sizes())) {
$video_size = array('width' => get_option($size . '_size_w'), 'height' => get_option($size . '_size_h'));
}
}
}
// refine video size
if ($gdlr_crop_video || $video_size['height'] == 9999) {
return array('width' => $video_size['width'], 'height' => intval($video_size['width'] / $ratio));
} else {
if ($video_size['width'] == 9999) {
return array('width' => intval($video_size['height'] * $ratio), 'height' => $video_size['height']);
}
}
return $video_size;
}