如何通过get请求调整图像大小?

时间:2015-08-06 18:37:08

标签: image dynamic get resize request

我见过几个网站会做以下事情:

example.com/test.png?w=100&h=100

使图像为100 x 100像素。

那些用作缩略图,然后如果你点击一个,那么该页面的一部分将改变以显示该图像,它是相同的,除了这次w和h请求不同:

example.com/test.png?w=500&h=500

(具体来说,我说的是Everlane ASCII code

有人可以向我解释一下吗?当那些获取变量被传递时究竟发生了什么?

1 个答案:

答案 0 :(得分:0)

在您提到的链接中,他们正在使用' Imgix'服务。但是没有它,你可以使用MVC框架(如codeigniter)实现类似的东西。

在这里,'我'在网页的url中是控制器中的函数名称。变量$ file将在' i'之后获得下一部分。在网址中。

了解它here

<?php
class Pages extends CI_Controller {

        public function i($file)
        {
           parse_str($_SERVER['QUERY_STRING'], $_GET);
           echo '<img src='.$file.' width='.$_GET['w'].' height='.$_GET['h'].'>';           
        }
}

**你还必须在config.php中启用get array

$config['allow_get_array'] = TRUE;