且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从远程源下载图像并调整大小然后保存

更新时间:2023-12-05 16:10:28

您可以尝试以下操作:

<?php    
$img = file_get_contents('http://www.site.com/image.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,'/images/myChosenName.jpg'); //save image as jpg

imagedestroy($thumb); 

imagedestroy($im);
?>


有关PHP图像功能的详细信息: http://www.php.net/manual/zh/ref.image.php


More information about PHP image function : http://www.php.net/manual/en/ref.image.php