wordpress中的图片在哪里调整大小?在数据库中?在文件夹中?
我将如何调整大小original图像(不创建新版本)。我问这个问题是因为我上传了相当多的图像,这些图像太大并且会减慢 WordPress 网站上的加载时间,并且我想调整它们的大小,以便没有任何尺寸大于 1500 像素。
我已经看过一些插件,包括“重新生成缩略图”,但可能有一个插件实际上可以实现我想要的功能,但我还没有找到。
好吧,图像“即时”调整大小,然后存储在服务器中,并将其信息记录在数据库中。
保留原始内容并生成所有“缩略图”。在这种情况下,“缩略图”是指 WP 生成的所有图像尺寸,无论大小。
我回答了同样的问题在 WordPress StackExchange。解决方案来自这篇文章:如何自动使用调整大小的图像而不是原始图像.
该脚本将用 WordPress 生成的大图像替换上传的图像(如果大于设置中定义的较大尺寸),以节省服务器空间,如果将缩略图链接到原始图像(例如灯箱),则可以节省带宽使用插件。
add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
function replace_uploaded_image($image_data)
{
// if there is no large image : return
if ( !isset($image_data['sizes']['large']) )
return $image_data;
// paths to the uploaded image and the large image
$upload_dir = wp_upload_dir();
$uploaded_image_location = $upload_dir['basedir'] . '/' . $image_data['file'];
$large_image_location = $upload_dir['path'] . '/' . $image_data['sizes']['large']['file'];
// delete the uploaded image
unlink($uploaded_image_location);
// rename the large image
rename($large_image_location, $uploaded_image_location);
// update image metadata and return them
$image_data['width'] = $image_data['sizes']['large']['width'];
$image_data['height'] = $image_data['sizes']['large']['height'];
unset($image_data['sizes']['large']);
return $image_data;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)