如何从PHP中的301重定向下载链接获取图像?

问题描述:

我正尝试使用PHP下载图像,以使用GD对其进行编辑。我找到了许多图像链接解决方案,但这是一个下载链接。

I'm trying to download this image with PHP to edit it with GD. I found many solutions for image links, but this one is a download link.

编辑:

$curl = curl_init("http://minecraft.net/skin/Notch.png");
$bin = curl_exec($curl);
curl_close($curl);
$img = @imagecreatefromstring($bin);

这是我当前的代码。它显示 301永久移动。我必须设置CURLOPT吗?

This is my current code. It displays "301 Moved Permanently". Are there CURLOPTs I have to set?

$curl = curl_init("http://minecraft.net/skin/Notch.png");
// Moved? Fear not, we'll chase it!
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
// Because you want the result as a string
curl_setopt($curl,  CURLOPT_RETURNTRANSFER, true); 
$bin = curl_exec($curl);
curl_close($curl);
$img = @imagecreatefromstring($bin);