how to resize image from url and make the size of the image smaller(如何从url调整图像大小并使图像的大小更小)
问题描述
我有一个带有美德模块的 joomla 网站.
I have a joomla website with the virtuemart module.
我拥有的是托管在其他域上的图像和缩略图.
What I have are images and thumbnails which are hosted on a other domain.
Virtuemart 给了我两个选择:
Virtuemart gives me 2 options:
1 - 浏览图片,会自动创建缩略图
1 - browse for image, a thumbnail will be automaticly created
2 - 输入外部托管图像的 URL,此选项没有调整大小选项
2 - enter a URL for a image which is external hosted, this option doesn't have a resize option
我克服这个问题的方法(当然有帮助)是为 img 标签设置一个 height="" 属性.唯一的问题是,当加载大图像时,即:500 x 700 像素,所谓的缩略图需要时间来加载,这是合乎逻辑的.
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.
谁能告诉我如何调整"来自 url 的图像的大小,从而减少加载缩略图的时间?
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?
就我个人而言,我正在考虑一种方法来降低来自带有代码、css 或其他任何内容的 url 调整大小的图像的图像质量?
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.
推荐答案
您可以使用 imagecopyresampled PHP 的功能.
You can make use of imagecopyresampled function of PHP.
示例程序(来源:php.net)
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);
?>
这篇关于如何从url调整图像大小并使图像的大小更小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从url调整图像大小并使图像的大小更小
基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01