从远程源下载图像并调整大小然后保存 [英] download image from remote source and resize then save
本文介绍了从远程源下载图像并调整大小然后保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你们中有人知道我可以使用它来从远程源下载图像,将其大小调整为120x120并使用我选择的文件名保存它吗?
Do any of you know of a good php class I can use to download an image from a remote source, re-size it to 120x120 and save it with a file name of my choosing?
因此,基本上,我将在"http://www.site.com/image.jpg"上拥有一个图像,并以120x120像素的格式保存到我的网络服务器"/images/myChosenName.jpg"中.
So basically I would have an image at "http://www.site.com/image.jpg" save to my web server "/images/myChosenName.jpg" as a 120x120 pixels.
谢谢
推荐答案
您可以尝试以下操作:
<?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
这篇关于从远程源下载图像并调整大小然后保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文