如何从网址调整图片大小,使图片的大小更小

Chr*_*ris 4 php url joomla resize image

我有一个带有virtuemart模块的joomla网站.

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

Virtuemart给了我两个选择:

1 - 浏览图像,将自动创建缩略图

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

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

是否有人可以选择如何"缩放"来自网址的图片作为缩略图缩短加载时间的结果?

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

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

cod*_*ict 13

您可以使用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);
?>
Run Code Online (Sandbox Code Playgroud)