php - 如何从url调整图像大小并缩小图像大小

标签 php image url joomla resize

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

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

Virtuemart 给了我两个选择:

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

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

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

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

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

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

最佳答案

您可以使用 imagecopyresampled PHP的功能。

示例程序(来源: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);
?>

关于php - 如何从url调整图像大小并缩小图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1960953/

相关文章:

php - 基于命令行、按计划的 Azure WebJobs - 不再可能了吗?

php - 使用 Codeception 运行现有的 Laravel 5.1 PHPUnit 测试

image - 如何更改IKImageBroswerView拖动图像

javascript - Javascript-如何在HTML页面上创建移动点

php - 在 MYSQL 搜索中使用 URL 参数

php - 其他语言中静态变量在 PHP 中的等价物是什么?

将字符串中的双引号更改为单引号的 PhpStorm 函数

java - 哪个 Java 类允许我显示图像占位符?

php - 使用 PHP 从 URL 中获取 "property og"元标记

php检查URL中是否有变量