如何在wordpress中调整原始图像的大小/访问? [英] How do I resize/access original images in wordpress?

查看:118
本文介绍了如何在wordpress中调整原始图像的大小/访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片在wordpress中的大小调整在哪里?在数据库中?在文件夹中?

Where do the images resize in wordpress? In a database? In a folder?

我将如何调整原始图像的大小(不创建新版本)。我问这个问题,因为我在wordpress网站上上传了相当多的图片太大而且加载时间减慢了,我想要调整它们的大小,以便没有任何大于1500px的尺寸。

How would I go about resizing the original image (not create a new version). I ask this, because I uploaded quite a few images that are too large and slow down load times on a wordpress site, and I want to resize them so there aren't any dimensions larger than 1500px.

我已经看过一些插件,包括重新生成缩略图,但可能有一个实际上做了我想要的,但我还没找到。

I've already looked at a few plugins, including "regenerate thumbnails", but there may be one that actually does what I want that I haven't been able to find yet.

推荐答案

好吧,图像会动态调整大小,然后存储在服务器中,并将其信息记录在数据库中。

Well, the images resize "on the fly", then stored in the server and its information recorded in the database.

原始遗骸和所有缩略图都会生成。在这种情况下,缩略图指的是所有WP生成的图像大小,无论大小。

The original remains and all "thumbnails" are generated. In this case, "thumbnails" refers to all WP generated image sizes, big or small.

我回答了同一个问题在WordPress StackExchange。而解决方案来自这篇文章:如何自动使用已调整大小的图像而不是原件

I answered the same question at WordPress StackExchange. And the solution comes from this article: How to automatically use resized images instead of originals.


此脚本将替换上传的图像(如果大于上面定义的较大尺寸)您的设置)由WordPress生成的大图像来节省服务器空间,并在将缩略图链接到原始图像时节省带宽,就像使用灯箱插件时一样。

This script will replace the uploaded image (if bigger than the larger size defined in your settings) by the large image generated by WordPress to save space in your server, and save bandwidth if you link a thumbnail to the original image, like when a lightbox plugin is used.



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;
}

这篇关于如何在wordpress中调整原始图像的大小/访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆