加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 17:27:57 所属栏目:PHP教程 来源:网络整理
导读:你们中的任何一个知道一个好的php类,我可以用来从远程源下载图像,将其重新设置为120×120,并使用我选择的文件名保存? 所以基本上我会在“http://www.site.com/image.jpg”上保存一个像120×120像素的网页服务器“/images/myChosenName.jpg”. 谢谢 你可以试
你们中的任何一个知道一个好的php类,我可以用来从远程源下载图像,将其重新设置为120×120,并使用我选择的文件名保存?

所以基本上我会在“http://www.site.com/image.jpg”上保存一个像120×120像素的网页服务器“/images/myChosenName.jpg”.

谢谢

你可以试试这个:
<?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,$newwidth,$newheight,$width,$height);

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

imagedestroy($thumb); 

imagedestroy($im);
?>

关于PHP图像功能的更多信息:http://www.php.net/manual/en/ref.image.php

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读