Php 从url下载并调整图像大小

Php 从url下载并调整图像大小,php,Php,这是我的代码: echo 'curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled'; echo ' - '; echo 'file_get_contents: ', file_get_contents(__FILE__) ? 'Enabled' : 'Disabled'; $img = file_get_contents('http://www.mundodeportivo.com/r/GODO/MD/p4/Barca

这是我的代码:

echo 'curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
echo ' - ';
echo 'file_get_contents: ', file_get_contents(__FILE__) ? 'Enabled' : 'Disabled';

$img = file_get_contents('http://www.mundodeportivo.com/r/GODO/MD/p4/Barca/Imagenes/2017/03/08/Recortada/MUNDODEPORTIVO_G_4519253-ktyD-U42659987163F0E-980x554@MundoDeportivo-Web.jpg');

$im = imagecreatefromstring($img);

$width = imagesx($im);

$height = imagesy($im);

$newwidth = '120';

$newheight = '120';

$thumb = imagecreatetruecolor($newwidth, $newheight);

imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

imagejpeg($thumb,'aaa.jpg'); //save image as jpg

imagedestroy($thumb); 

imagedestroy($im);
您可以在此处进行测试:


为什么不起作用?

我测试了你的代码,它工作正常,出现了什么错误?@Jabs,如你所见()保存的图像是空的。为什么?嗯,我不确定,但你可以在另一台服务器上试试,因为在我这边,我可以看到调整大小的冲浪image@Jabs只是在另一台服务器上尝试过,它确实可以工作。但是我想知道为什么它不能在这台服务器上工作:)可能是一些图像库/扩展问题,以确认您可以比较两台服务器上的版本