解决WordPress图片生成多张缩略图的几种方法
对于网站运营人员来说,网站备份是很重要的。最近我在备份网站数据时,也就几天时间,发现备份的压缩文件增加了好几十M,由于是新的网站,所以这种增长速度是非常快的。于是小编赶紧登陆centos7系统后台看了下,发现主要是增加了图片的存储大小。
细心的看了下,明明是一张清晰的图片,硬生生的被系统生成了很多张不同的缩略图。由于我的是博客网站,所以不需要这么多的缩略图,也占用空间,于是赶紧网上找资料来解决此问题。下面简单说说中方法。

第一种、在WordPress后台进行设置
基本处理这个问题,只要在仪表盘->设置->媒体里把缩略图禁止即可,见图示操作。
第二种、在functions.php文件中进行修改
按照第一种方法设置完之后,可能会发现果然继续上传图片的时候只有一张。然而在上传一张高清图片的时候突然发现又多了一张另外尺寸的图片,有的比原始尺寸还大。而且尺寸不一样,于是在functions.php文件(themolio
主题)看到以下代码:
|
function themolio_setup() {
/* Make Themolio available for translation.
* Translations can be added to the /languages/ directory.
* If you're building a theme based on Themolio, use a find and replace
* to change 'themolio' to the name of your theme in all the template files.
*/
load_theme_textdomain('themolio', get_template_directory().'/languages' );
add_editor_style();
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
/**
* This sets up the image size for the grid based top-down layouts (with no sidebar).
* If you change the width/height of your content,
* you will have to modify the width and height mentioned below as well
*/
add_image_size('themolio-two-col-grid-image-nosidebar',460,300,true);
add_image_size('themolio-three-col-grid-image-nosidebar',290,200,true);
add_image_size('themolio-four-col-grid-image-nosidebar',210,150,true);
/**
* This sets up the image size for the grid based top-down layouts (with sidebar).
* If you change the width/height of your content,
* you will have to modify the width and height mentioned below as well
*/
add_image_size('themolio-two-col-grid-image-sidebar',356,250,true);
add_image_size('themolio-three-col-grid-image-sidebar',230,150,true);
add_image_size('themolio-four-col-grid-image-sidebar',171,110,true);
/**
* This sets up the image size for the featured image.
* If you change the width/height of your content,
* you will have to modify the width and height mentioned below as well
*/
add_image_size('themolio-featured-image',800,300,true);
register_nav_menu('primary', __('Primary Menu', 'themolio'));
add_theme_support('post-formats', array('link', 'gallery', 'status', 'quote', 'image', 'video'));
if(themolio_is_wp_version('3.4')) {
add_theme_support('custom-background');
} else {
add_custom_background();
}
}
|
其中add_image_size就是增加了尺寸设置的方法,根据需要注释掉即可。其他主题也可以依此类推,只要搜索关键字add_image_size就可以了。
安装上面方法删除了add_image_size,再次上传图片看看,发现各种小的尺寸都没有了,也清爽多了。但是还会多了两种大尺寸图片,比原来尺寸还大,这一般是像素宽超过700PX的图片自动生成medium large尺寸的图片,大概700*300多PX,有的是1024*502等等。。如果遇到这种情况可以继续修改functions.php文件。
把以下代码直接放入functions.php里就可以生效了,注意此代码对之前已经上传完的图无效,之前生成的缩略图需要自行删除。
|
/**
* 禁止生成768*516图片
*/
add_filter( 'intermediate_image_sizes', function( $sizes )
{
return array_filter( $sizes, function( $val )
{
return 'medium_large' !== $val; // Filter out 'medium_large'
} );
} );
|
栏 目:PHP教程
下一篇:PHP 7安装使用体验之性能大提升,兼容性强,扩展支
本文标题:PHP中实现九九乘法口诀表
本文地址:http://tp2.com/index.php?m=home&c=View&a=index&aid=172
您可能感兴趣的文章
- 11-23PHP面向对象 封装与继承
- 11-23PHP 7安装使用体验之性能大提升,兼容性强,扩展支
- 11-23PHP中实现九九乘法口诀表
- 11-23PHP中实现一个简易三角形的方法
- 11-23PHP中利用for循环判断一个数是不是回文数
- 11-23隐藏PHP版本与PHP基本安全设置
- 11-23nginx+php 打开php错误提示的方法
- 11-23php中 == 和 === 的区别和应用说明
- 11-23PHP常用正则表达式汇总大全
- 11-23PHP保留两位小数的几种方法


阅读排行
推荐教程
- 11-22PHP自定义函数判断是否为Get、Post及Ajax提交的方法
- 11-23php中 == 和 === 的区别和应用说明
- 11-23PHP 7安装使用体验之性能大提升,兼容性强,扩展支
- 11-23隐藏PHP版本与PHP基本安全设置
- 11-23PHP+MYSQL 读写分离简单实战
- 11-22详解PHP防止直接访问.php 文件的实现方法
- 11-22PHP编程求最大公约数与最小公倍数的方法示例
- 11-22PHP实现上传多图即时显示与即时删除的方法
- 11-23PHP保留两位小数的几种方法
- 11-23nginx+php 打开php错误提示的方法
