如何从url调整图像大小并使图像尺寸变小

发布于 2024-08-16 00:46:20 字数 421 浏览 1 评论 0原文

我有一个 joomla 网站,其中包含 virtualmart 模块。

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

Virtuemart 给了我 2 个选项:

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

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

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

有人可以告诉我如何“调整”来自 url 的图像的大小,从而减少缩略图加载时间吗?

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

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

I have a joomla website with the virtuemart module.

What I have are images and thumbnails which are hosted on a other domain.

Virtuemart gives me 2 options:

1 - browse for image, a thumbnail will be automaticly created

2 - enter a URL for a image which is external hosted, this option doesn't have a resize option

The way I have overcome this problem (with help ofcourse) is to set a height="" attribute to the img tag. The only problem is that when a big image is loaded ie: 500 x 700 px, the so called thumbnail takes time to load, this is logical.

Can someone give me options how a image from a url can be "resized" with as outcome that the thumbnail takes less time to load?

Personally I was thinking about a way to decrease the image quality of the resized image which comes from a url with a code, css or anything else?

I know this has less to do with solving a code, but I know you guys know more options then I do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风柔一江水 2024-08-23 00:46:20

您可以使用 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);
?>

You can make use of imagecopyresampled function of PHP.

Sample program (source: 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);
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文