如何从网址调整图片大小,使图片的大小更小 [英] how to resize image from url and make the size of the image smaller

查看:210
本文介绍了如何从网址调整图片大小,使图片的大小更小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有virtuemart模块的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给了我2个选项:

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.

有人可以给我选项如何缩放网址中的图片作为缩放图片加载时间较短的结果?

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或其他任何内容的网址?

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.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);
?>

这篇关于如何从网址调整图片大小,使图片的大小更小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆