如何使用PHP从URL调整图像大小?

时间:2015-06-13 13:45:07

标签: php

我正在接收来自网址的图片,我想将这些图片保存到三个不同大小的新目录中。我已经在这里获取了URL,现在我只需要一种方法来调整每个图像的大小,具有特定的高度和宽度。

我不想调整上传图片的大小,只调整特定网址的图片。

我的代码:

$content = file_get_contents('http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg');
$name = "http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg";
$parts = explode('.', $name);
$new_url = rand(0, pow(10, 5)) . '_' . time() . '.' . $parts[count($parts) - 1];
file_put_contents(DIRECTORY.'/' . $new_url , $content);

我该怎么做?感谢。

1 个答案:

答案 0 :(得分:0)

这是基于render()(GD库)http://php.net/manual/en/function.imagecopyresampled.php

的解决方案
imagecopyresampled