从网址下载并调整图片大小

时间:2017-03-10 11:38:56

标签: 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/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);

您可以在此处测试:

http://aszx.altervista.org/saveimgfromurl/index.php

http://aszx.altervista.org/saveimgfromurl/aaa.jpg

为什么不起作用?

0 个答案:

没有答案