Iva*_*var 11 php image-resizing
你们有没有知道一个很好的php类我可以用来从远程源下载图像,将其重新调整为120x120并用我选择的文件名保存?
所以基本上我会在"http://www.site.com/image.jpg"上有一个图像保存到我的网络服务器"/images/myChosenName.jpg"为120x120像素.
谢谢
Zul*_*rul 17
你可以试试这个:
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
有关PHP图像功能的更多信息:http://www.php.net/manual/en/ref.image.php
| 归档时间: |
|
| 查看次数: |
10426 次 |
| 最近记录: |