Begin主题使用又拍云(Upyun)图像处理功能-替换thumbnail缩略图,提升服务器性能

自然 2019年9月20日19:44:09 评论 62

Begin在本次更新中加入了阿里云OSS缩略图功能,已经包含了默认缩略图(thumbnail)、阿里云OSS缩略图、七牛缩略图,鸟哥后续可能会持续加入更多的缩略图服务支持。我们知道默认缩略图使用thumbnail.php对缩略图进行剪裁,但是经过thumbnail漏洞,网站图片数量众多,生成缩略图很多时服务器压力骤增。

自然的博客展示的图片数量才20几张,有些小伙伴的网站一页图片高达100+张,可谓是恐怖如斯。在考虑了性能与安全的前提下,自然建议各位将缩略图服务外置。使用其它主题的站长可以使用wpjam插件直接对接骑牛缩略图服务;使用Begin主题的站长,可以直接在主题选项-基本设置-缩略图方式下选择适合自己的缩略图方式。可以轻松接入阿里云OSS缩略图服务、七牛缩略图服务。

Begin主题使用又拍云(Upyun)图像处理功能-替换thumbnail缩略图,提升服务器性能

自然使用又拍云(Upyun)作为附件加速,所有的图片全部走又拍云CDN进行加速,极大程度降低了服务器负载压力。网络上关于Wordpress使用又拍云缩略图的相关教程很少,几乎不具备参考价值。自然通过查看Begin内置的阿里云OSS缩略图服务的文件理解了调用策略,并将它经过更高,使其适配又拍云服务。

又拍云图像处理服务

又拍云作为主流CDN之一,在数据无缝迁移、性能优化、访问控制、边缘计算、图像处理方面都拥有成熟的解决方案。期中图像处理服务是今天讲到的重点,又拍云的图像处理模式采用URL+间隔标识符号+处理规,如:http://test_domain/pic.jpg!hi, pic.jpg 为文件路径,hi 为版本名称。

我们首先来预设一些图形处理规则,登陆又拍云进入CDN设置-图片处理选项下:

设置间隔标识符

Begin主题使用又拍云(Upyun)图像处理功能-替换thumbnail缩略图,提升服务器性能

 

通过又拍云官网介绍,我们可以知道又拍云支持使用半角的“!”,“-”,“_”作为间隔标识符号,经过自然的实际测试及一段时间使用观察记录,这里自然推荐使用“!”作为间隔标识符号。如果使用“-”作为标识符号,可能会和目录结构产生冲突,例如http://test_domain/upload/2019-8/pic.jpg-hi的格式,系统可能错误判断-8/pic.jpg-hi一整串字符为标识符号。

设置自定义图形版本

按照上面说明的格式,选择好间隔标识符号后,我们还需要设置图像处理策略,这里要注意一点版本创建后,版本名称将不允许修改,最好一次完成预设。如果错误也不要紧,删除重来即可;

Begin主题使用又拍云(Upyun)图像处理功能-替换thumbnail缩略图,提升服务器性能

这里我们可以设置缩略图的尺寸,以便完成所需要的裁剪。建议勾选锐化图片选项,这个选项可以在一定程度上提升图像的清晰度。自然使用的缩略图版本名称为upyun.oss.h.210.w.280.limit.0,一定要设置名称凸显图片尺寸,以方便识别。

Begin主题文件修改

这里自然使用了阿里云OSS的文件作文范本修改,修改thumbnail-oss.php (inc/thumbnail-oss.php),自然将其中关于阿里云OSS的缩略图引用策略全部替换成了又拍云的。

展开

<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
// 标准缩略图
function zm_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
					echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a>';			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<a href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a>';
				} else { 
					echo '<a href="'.get_permalink().'"><img src="'. $src .'" alt="'.$post->post_title .'" /></a>';
				}
			}
		}
	}
}

function zm_thumbnail_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a></span>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').',w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></span>';
				} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a></span>';
				} else { 
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'. $src .'" alt="'.$post->post_title .'" /></a></span>';
				}
			}
		}
	}
}

// 分类宽缩略图
function zm_long_thumbnail() {
	global $post;
	if ( get_post_meta($post->ID, 'long_thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'long_thumbnail', true);
		echo '<a href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_k_w').'&h='.zm_get_option('img_k_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_k_w').'&h='.zm_get_option('img_k_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('long', array('alt' => get_the_title()));
			}
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_k_h').',w.'.zm_get_option('img_k_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
			} else { 
				echo '<a class="random-img" href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/img/random/long.jpg" alt="'.$post->post_title .'" /></a>';
			}
		}
	}
}

function zm_long_thumbnail_h() {
	global $post;
	if ( get_post_meta($post->ID, 'long_thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'long_thumbnail', true);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/long.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_k_w').'&h='.zm_get_option('img_k_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_k_w').'&h='.zm_get_option('img_k_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('long', array('alt' => get_the_title()));
			}
			echo '</a></span>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/long.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_k_h').',w.'.zm_get_option('img_k_w').'.limit.0" alt="'.$post->post_title .'" /></a></span>';
			} else { 
				echo '<span class="load"><a class="random-img" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/long.png" data-original="'.get_template_directory_uri().'/img/random/long.jpg" alt="'.$post->post_title .'" /></a></span>';
			}
		}
	}
}

// 图片缩略图
function img_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_i_w').'&h='.zm_get_option('img_i_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_i_w').'&h='.zm_get_option('img_i_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_i_h').',w.'.zm_get_option('img_i_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<span class="load"><a href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_i_w').'&h='.zm_get_option('img_i_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a></span>';
				} else { 
					echo '<a href="'.get_permalink().'"><img src="'.$src .'" alt="'.$post->post_title .'" /></a>';
				}
			}
		}
	}
}

function img_thumbnail_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_i_w').'&h='.zm_get_option('img_i_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_i_w').'&h='.zm_get_option('img_i_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a></span>';;
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_i_h').',w.'.zm_get_option('img_i_w').'.limit.0" alt="'.$post->post_title .'" /></a></span>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_i_w').'&h='.zm_get_option('img_i_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a>';
				} else { 
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'. $src .'" alt="'.$post->post_title .'" /></a></span>';
				}
			}
		}
	}
}

// 视频缩略图
function videos_thumbnail_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'small', true) ) {
		$image = get_post_meta($post->ID, 'small', true);
		echo '<span class="load"><a class="videos" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a class="videos" href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '<i class="be be-play"></i></a></span>';

			} else {
				$content = $post->post_content;
				preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
				$n = count($strResult[1]);
				if($n > 0){
					echo '<span class="load"><a class="videos" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_v_h').'.w.'.zm_get_option('img_v_w').'.limit.0" ';
					echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
					} else { 
						if ( zm_get_option('rand_img_n') ) {
							$random = mt_rand(1, zm_get_option('rand_img_n'));
						} else { 
							$random = mt_rand(1, 5);
						}
						if (zm_get_option('clipping_rand_img')) {
							echo '<span class="load"><a class="videos" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
						} else { 
							echo '<span class="load"><a class="videos" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'. $src .'" ';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
						}
					}
			}
	}
}

function videos_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'small', true) ) {
		$image = get_post_meta($post->ID, 'small', true);
		echo '<a class="videos" href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a class="videos" href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
	        echo '<i class="be be-play"></i></a>';
			} else {
				$content = $post->post_content;
				preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
				$n = count($strResult[1]);
				if($n > 0){
					echo '<a class="videos" href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_v_h').'.w.'.zm_get_option('img_v_w').'.limit.0" ';
					echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
					} else { 
						if ( zm_get_option('rand_img_n') ) {
							$random = mt_rand(1, zm_get_option('rand_img_n'));
						} else { 
							$random = mt_rand(1, 5);
						}

						if (zm_get_option('clipping_rand_img')) {
							echo '<a class="videos" href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
						} else { 
							echo '<a class="videos" href="'.get_permalink().'"><img src="'. $src .'" ';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
						}
					}
			}
	}
}

function videoe_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'small', true) ) {
		$image = get_post_meta($post->ID, 'small', true);
		echo '<img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" />';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_v_h').'.w.'.zm_get_option('img_v_w').'.limit.0" ';
			echo ' alt="'.$post->post_title .'" />';
		} else { 
			if ( zm_get_option('rand_img_n') ) {
				$random = mt_rand(1, zm_get_option('rand_img_n'));
			} else { 
				$random = mt_rand(1, 5);
			}
			if (zm_get_option('clipping_rand_img')) {
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1" ';
				echo ' alt="'.$post->post_title .'" />';
			} else { 
				echo '<img src="'. $src .'" ';
				echo ' alt="'.$post->post_title .'" />';
			}
		}
	}
}

function videor_thumbnail_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'small', true) ) {
		$image = get_post_meta($post->ID, 'small', true);
		echo '<span class="load"><a class="videor" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a class="videor" href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '<i class="be be-play"></i></a></span>';
			} else {
				$content = $post->post_content;
				preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
				$n = count($strResult[1]);
				if($n > 0){
					echo '<span class="load"><a class="videor" href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_v_h').'.w.'.zm_get_option('img_v_w').'.limit.0" ';
					echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
					} else { 
						if ( zm_get_option('rand_img_n') ) {
							$random = mt_rand(1, zm_get_option('rand_img_n'));
						} else { 
							$random = mt_rand(1, 5);
						}
						if (zm_get_option('clipping_rand_img')) {
							echo '<span class="load"><a class="videor" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1" ';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
						} else { 
							echo '<span class="load"><a class="videor" href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'. $src .'" ';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a></span>';
						}
					}
			}
	}
}

function videor_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'small', true) ) {
		$image = get_post_meta($post->ID, 'small', true);
		echo '<a class="videor" href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a class="videor" href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '<i class="be be-play"></i></a>';
			} else {
				$content = $post->post_content;
				preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
				$n = count($strResult[1]);
				if($n > 0){
					echo '<a class="videor" href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_v_h').'.w.'.zm_get_option('img_v_w').'.limit_." ';
					echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
					} else { 
						if ( zm_get_option('rand_img_n') ) {
							$random = mt_rand(1, zm_get_option('rand_img_n'));
						} else { 
							$random = mt_rand(1, 5);
						}
						if (zm_get_option('clipping_rand_img')) {
							echo '<a class="videor" href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_v_w').'&h='.zm_get_option('img_v_h').'&a='.zm_get_option('crop_top').'&zc=1" ';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
						} else { 
							echo '<a class="videor" href="'.get_permalink().'"><img src="'. $src .'" ';
							echo ' alt="'.$post->post_title .'" /><i class="be be-play"></i></a>';
						}
					}
			}
	}
}

// 商品缩略图
function tao_thumbnail() {
		global $post;
		$url = get_post_meta($post->ID, 'taourl', true);
		if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.esc_url( get_permalink() ).'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_t_w').'&h='.zm_get_option('img_t_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_t_w').'&h='.zm_get_option('img_t_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('tao', array('alt' => get_the_title()));
			}
			echo '</a>';
			} else {
				$content = $post->post_content;
				preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
				$n = count($strResult[1]);
				if($n > 0){
					echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_t_h').'.w.'.zm_get_option('img_t_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
				}
			}
	}
}

function tao_thumbnail_h() {
		global $post;
		$url = get_post_meta($post->ID, 'taourl', true);
		if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<span class="load"><a href="'.esc_url( get_permalink() ).'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_t_w').'&h='.zm_get_option('img_t_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_t_w').'&h='.zm_get_option('img_t_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('tao', array('alt' => get_the_title()));
			}
			echo '</a></span>';
			} else {
				$content = $post->post_content;
				preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
				$n = count($strResult[1]);
				if($n > 0){
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_t_h').'.w.'.zm_get_option('img_t_w').'.limit.0" alt="'.$post->post_title .'" /></a></span>';
				}
			}
	}
}

// 图像日志缩略图
function format_image_thumbnail() {
    global $post;
	$content = $post->post_content;
	preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
	echo '<div class="f4"><div class="format-img"><a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div>';
	echo '<div class="f4"><div class="format-img"><a href="'.get_permalink().'"><img src="'.$strResult[1][1].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div>';
	echo '<div class="f4"><div class="format-img"><a href="'.get_permalink().'"><img src="'.$strResult[1][2].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div>';
	echo '<div class="f4"><div class="format-img"><a href="'.get_permalink().'"><img src="'.$strResult[1][3].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div>';
}

function format_image_thumbnail_h() {
    global $post;
	$content = $post->post_content;
	preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
	echo '<div class="f4"><div class="format-img"><div class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div></div>';
	echo '<div class="f4"><div class="format-img"><div class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][1].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div></div>';
	echo '<div class="f4"><div class="format-img"><div class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][2].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div></div>';
	echo '<div class="f4"><div class="format-img"><div class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][3].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div></div></div>';
}

function zm_ad_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	$direct = get_post_meta($post->ID, 'direct', true);
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a href="'.$direct.'" target="_blank" rel="nofollow">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<a href="'.$direct.'" target="_blank" rel="nofollow"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<a href="'.$direct.'" target="_blank" rel="nofollow"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a>';
				} else { 
					echo '<a href="'.$direct.'" target="_blank" rel="nofollow"><img src="'.$src .'" alt="'.$post->post_title .'" /></a>';
				}
			}
		}
	}
}

function zm_ad_thumbnail_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	$direct = get_post_meta($post->ID, 'direct', true);
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<span class="load"><a href="'.$direct.'" target="_blank" rel="nofollow"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a href="'.$direct.'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a></span>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<span class="load"><a href="'.$direct.'" target="_blank" rel="nofollow"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></span>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<span class="load"><a href="'.$direct.'" target="_blank" rel="nofollow"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a></span>';
				} else { 
					echo '<span class="load"><a href="'.$direct.'" target="_blank" rel="nofollow"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'. $src .'" alt="'.$post->post_title .'" /></a></span>';
				}
	        }
		}
	}
}

// 图片布局缩略图
function zm_grid_thumbnail() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.get_permalink().'"><img src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('grid_w').'&h='.zm_get_option('grid_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('grid_w').'&h='.zm_get_option('grid_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('grid_h').'.w.'.zm_get_option('grid_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<a href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('grid_w').'&h='.zm_get_option('grid_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a>';
				} else { 
					echo '<a href="'.get_permalink().'"><img src="'. $src .'" alt="'.$post->post_title .'" /></a>';
				}
			}
		}
	}
}

function zm_grid_thumbnail_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('grid_w').'&h='.zm_get_option('grid_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<span class="load"><a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="' . get_template_directory_uri() . '/img/loading.png" data-original='.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('grid_w').'&h='.zm_get_option('grid_h').'&a='.zm_get_option('crop_top').'&zc=1 alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a></span>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('grid_h').'.w.'.zm_get_option('grid_w').'.limit.0" alt="'.$post->post_title .'" /></a></span>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('grid_w').'&h='.zm_get_option('grid_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a></span>';
				} else { 
					echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$src .'" alt="'.$post->post_title .'" /></a></span>';
				}
			}
		}
	}
}

// 宽缩略图分类
function zm_full_thumbnail() {
	global $post;
	if ( get_post_meta($post->ID, 'full_thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'full_thumbnail', true);
		echo '<header class="full-header"><figure class="full-thumbnail"><span class="load"><a href="'.get_permalink().'"><img src=';
		echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w=900&h=350&a=t&zc=1';
		echo ' alt="'.$post->post_title .'" /></a></span></figure>';
		echo ''.the_title( sprintf( '<h2 class="entry-title-img"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ).'</header>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<header class="full-header"><figure class="full-thumbnail"><span class="load"><a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.350.w.900.limit.0" alt="'.$post->post_title .'" /></a></span></figure>';
			echo ''.the_title( sprintf( '<h2 class="entry-title-img"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ).'</header>';
		} else {
			the_title( sprintf( '<h2 class="entry-title-full"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
			echo '<span class="title-l"></span>';
		}
	}
}

function zm_full_thumbnail_h() {
	global $post;
	if ( get_post_meta($post->ID, 'full_thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'full_thumbnail', true);
		echo '<header class="full-header"><figure class="full-thumbnail"><span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w=900&h=350&a=t&zc=1';
		echo ' alt="'.$post->post_title .'" /></span></figure>';
		echo ''.the_title( sprintf( '<h2 class="entry-title-img"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ).'</header>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<header class="full-header"><figure class="full-thumbnail"><span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.350.w.900.limit.0" alt="'.$post->post_title .'" /></a></span></figure>';
			echo ''.the_title( sprintf( '<h2 class="entry-title-img"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ).'</header>';
		} else {
			the_title( sprintf( '<h2 class="entry-title-full"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
			echo '<span class="title-l"></span>';
		}
	}
}

// 网址缩略图
function zm_sites_thumbnail() {
	global $post;
	$sites_img_link = sites_nofollow( base64_encode(get_post_meta($post->ID, 'sites_img_link', true)));
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.$sites_img_link.'" target="_blank" rel="external nofollow"><img src=';
		echo $image;
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<a href="'.$sites_img_link.'" target="_blank" rel="external nofollow"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
		}
	}
}

function zm_sites_thumbnail_h() {
	global $post;
	$sites_img_link = sites_nofollow( base64_encode(get_post_meta($post->ID, 'sites_img_link', true)));
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.$sites_img_link.'" target="_blank" rel="external nofollow"><img src=';
		echo $image;
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<div class="load"><a href="'.$sites_img_link.'" target="_blank" rel="external nofollow"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a></div>';
		}
	}
}

// wd_img
function gr_wd_thumbnail() {
	global $post;
	if ( get_post_meta($post->ID, 'wd_img', true) ) {
		$image = get_post_meta($post->ID, 'wd_img', true);
		echo '<a href="'.get_permalink().'"><img src=';
		echo $image;
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.380.w.700.limit.0" alt="'.$post->post_title .'" /></a>';
	}
}

function gr_wd_thumbnail_h() {
	global $post;
	if ( get_post_meta($post->ID, 'wd_img', true) ) {
		$image = get_post_meta($post->ID, 'wd_img', true);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		echo $image;
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$strResult[1][0].'!upyun.oss.h.380.w.700.limit.0" alt="'.$post->post_title .'" /></a></span>';
	}
}

// slider_widge
function zm_widge_thumbnail() {
	global $post;
	if ( get_post_meta($post->ID, 'widge_img', true) ) {
		$image = get_post_meta($post->ID, 'widge_img', true);
		echo '<a href="'.get_permalink().'"><img src=';
		echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_s_w').'&h='.zm_get_option('img_s_h').'&a='.zm_get_option('crop_top').'&zc=1';
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_s_h').'.w.'.zm_get_option('img_s_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
		}
	}
}

// slider_scrolling
function zm_thumbnail_scrolling() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'thumbnail', true) ) {
		$image = get_post_meta($post->ID, 'thumbnail', true);
		echo '<a href="'.get_permalink().'"><img class="owl-lazy" data-src=';
		if (zm_get_option('manual_thumbnail')) {
			echo get_template_directory_uri().'/thumbnail.php?src='.$image.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1';
		} else {
			echo $image;
		}
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		if ( has_post_thumbnail() ) {
			echo '<a href="'.get_permalink().'">';
			if (zm_get_option('clipping_thumbnails')) {
				$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
				echo '<img src="'.get_template_directory_uri().'/thumbnail.php?src='.$full_image_url[0].'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.get_the_title().'">';
			} else {
				the_post_thumbnail('content', array('alt' => get_the_title()));
			}
			echo '</a>';
		} else {
			$content = $post->post_content;
			preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
			$n = count($strResult[1]);
			if($n > 0){
				echo '<a href="'.get_permalink().'"><img class="owl-lazy" data-src="'.$strResult[1][0].'!upyun.oss.h.'.zm_get_option('img_h').'.w.'.zm_get_option('img_w').'.limit.0" alt="'.$post->post_title .'" /></a>';
			} else { 
				if ( zm_get_option('rand_img_n') ) {
					$random = mt_rand(1, zm_get_option('rand_img_n'));
				} else { 
					$random = mt_rand(1, 5);
				}
				if (zm_get_option('clipping_rand_img')) {
					echo '<a href="'.get_permalink().'"><img class="owl-lazy" data-src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a>';
				} else { 
					echo '<a href="'.get_permalink().'"><img class="owl-lazy" data-src="'. $src .'" alt="'.$post->post_title .'" /></a>';
				}
			}
		}
	}
}

// waterfall
function zm_waterfall_img() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'fall_img', true) ) {
		$image = get_post_meta($post->ID, 'fall_img', true);
		echo '<a href="'.get_permalink().'"><img src=';
		echo $image;
		echo ' alt="'.$post->post_title .'" /></a>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'" alt="'.$post->post_title .'" /></a>';
		} else { 
			if ( zm_get_option('rand_img_n') ) {
				$random = mt_rand(1, zm_get_option('rand_img_n'));
			} else { 
				$random = mt_rand(1, 5);
			}
			if (zm_get_option('clipping_rand_img')) {
				echo '<a href="'.get_permalink().'"><img src="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a>';
			} else { 
				echo '<a href="'.get_permalink().'"><img src="'.$src .'" alt="'.$post->post_title .'" /></a>';
			}
		}
	}
}

function zm_waterfall_img_h() {
	$random_img = explode(',' , zm_get_option('random_image_url'));
	$random_img_array = array_rand($random_img);
	$src = $random_img[$random_img_array];
	global $post;
	if ( get_post_meta($post->ID, 'fall_img', true) ) {
		$image = get_post_meta($post->ID, 'fall_img', true);
		echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original=';
		echo $image;
		echo ' alt="'.$post->post_title .'" /></a></span>';
	} else {
		$content = $post->post_content;
		preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
		$n = count($strResult[1]);
		if($n > 0){
			echo '<span class="load"><a href="'.get_permalink().'"><img src="'.$strResult[1][0].'" alt="'.$post->post_title .'" /></a></span>';
		} else { 
			if ( zm_get_option('rand_img_n') ) {
				$random = mt_rand(1, zm_get_option('rand_img_n'));
			} else { 
				$random = mt_rand(1, 5);
			}
			if (zm_get_option('clipping_rand_img')) {
				echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.get_template_directory_uri().'/thumbnail.php?src='.$src.'&w='.zm_get_option('img_w').'&h='.zm_get_option('img_h').'&a='.zm_get_option('crop_top').'&zc=1" alt="'.$post->post_title .'" /></a></span>';
			} else { 
				echo '<span class="load"><a href="'.get_permalink().'"><img src="' . get_template_directory_uri() . '/img/loading.png" data-original="'.$src .'" alt="'.$post->post_title .'" /></a></span>';
			}
		}
	}
}

自然已经将修改后的thumbnail-oss.php文件放在底部,请自行下载。

主题选项设置

又拍云方面的设置和修改代码的部分我们已经完成配置,接下来就是在Begin主题选项下启用又拍云的缩略图功能就可以去体验又拍云的图像处理服务了。

Begin主题使用又拍云(Upyun)图像处理功能-替换thumbnail缩略图,提升服务器性能

总结

Begin主题使用又拍云的基本设置步骤就是这样,这个教程具备通用性,操作比较复杂。自然会继续研究优化操作方法,如果你有独到见解,不妨留言告诉我们。这里自然要补充一点,自然使用了CDN Enabler插件将图片全部重定向到了又拍云CDN上面。如果你使用其他网站缓存插件已经完成图片的重定向服务则可以直接使用。如果你不想使用插件,也可以参考自然的文章《又拍云加速wordpress静态文件访问-为图片加入内容分发服务

下载信息 分享文件(夹):thumbnail-oss.zip Nginx/php
下载地址
weinxin
网科文媒
快来关注一下,你想要的这里都有喔!
自然

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: