【问题标题】:how to resize image from url and make the size of the image smaller如何从 url 调整图像大小并使图像的大小更小
【发布时间】:2010-12-29 23:27:48
【问题描述】:

我有一个 joomla 网站,里面有 mercurialmart 模块。

我拥有的是托管在其他域上的图像和缩略图。

Virtuemart 给了我两个选择:

1 - 浏览图片,会自动生成缩略图

2 - 输入外部托管图像的 URL,此选项没有调整大小选项

我克服这个问题的方法(当然有帮助)是为 img 标签设置一个 height="" 属性。唯一的问题是,当加载一个大图像时,即:500 x 700 px,所谓的缩略图需要时间来加载,这是合乎逻辑的。

有人可以给我选项,如何“调整”来自 url 的图像,从而减少加载缩略图的时间?

就我个人而言,我正在考虑一种方法来降低来自带有代码、css 或其他任何内容的 url 的调整大小图像的图像质量?

我知道这与解决代码关系不大,但我知道你们知道的选择比我多。

【问题讨论】:

    标签: php image url joomla resize


    【解决方案1】:

    你可以使用PHP的imagecopyresampled函数。

    示例程序(来源:php.net)

    <?php
    // The file
    $filename = 'http://valplibrary.files.wordpress.com/2009/01/5b585d_merry-christmas-blue-style.jpg';
    $percent = 0.5; // percentage of resize
    
    // Content type
    header('Content-type: image/jpeg');
    
    // Get new dimensions
    list($width, $height) = getimagesize($filename);
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    
    // Resample
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
    // Output
    imagejpeg($image_p, null, 100);
    ?>
    

    【讨论】:

    猜你喜欢
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 2012-12-02
    相关资源
    最近更新 更多