Home > Backend Development > PHP Tutorial > php远程怎么获取图片

php远程怎么获取图片

PHPz
Release: 2020-09-05 14:00:47
Original
2362 people have browsed it

php远程获取图片的方法:首先通过“imagecreate”函数创建画布;然后通过“getimagesize”获取图片信息;接着使用“imagecreatefromjpeg”方法对获取的图片进行处理即可。

php远程怎么获取图片

php远程怎么获取图片?php远程获取图片并处理

通常我们要创建图像时会使用

//创建画布
$img=imagecreate(500,500);
$path = './test.jpeg';
获取图片信息,调用不同方法
//获取图片信息
$img_info = getimagesize($path);
 
//获取图片类型,jpg等
$type = image_type_to_extension($info[2], false);
 
//获取相应方法
$func = "imagecreatefrom{$type}";
但当我们要获取已有的图片进行处理时,可以使用 imagecreatefromjpeg 方法
//$img=imagecreatefromjpeg('https://b-ssl.duitang.com/uploads/item/201607/04/20160704052649_WLyfB.jpeg');
$img=$func($path);
Copy after login

代码如下

<?php
//$img=imagecreatefromjpeg(&#39;https://b-ssl.duitang.com/uploads/item/201607/04/20160704052649_WLyfB.jpeg&#39;);
    $path = &#39;./test.jpeg&#39;;
 
    //获取图片信息
    $img_info = getimagesize($path);
 
    //获取图片类型,jpg等
    $type = image_type_to_extension($info[2], false);
 
    //获取相应方法
    $func = "imagecreatefrom{$type}";
 
$img=$func($path );
//设置颜色
//背景色
$white=imagecolorallocate($img,255,255,255);
//画笔
$black=imagecolorallocate($img,0,0,0);
//矩形
imagerectangle($img,100,100,300,300,$black);
ob_clean();
header(&#39;Content-type:image/jpeg&#39;);
imagejpeg($img) or die(&#39;创建图形失败&#39;);
imagedestroy($img);
?>
Copy after login

 更多相关知识,请访问PHP中文网

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template