php 干预图像:直接从带有原始文件名和扩展名的 url 保存图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32828606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Intervention Image: Save image directly from an url with original file name and ext?
提问by Salines
How to get the filename, when taking image from a remote server? And how to save with original size and filename?
从远程服务器获取图像时如何获取文件名?以及如何以原始大小和文件名保存?
// Take remote image
$img = Image::make('http://image.info/demo.jpg');
// how to save in the img/original/demo.jpg
$img->save(????);
I use Intervention,(http://image.intervention.io/api/make) to build CakePHP 3 image Behavior, I want to provide an easy uploading from remote servers, and keep the original image as a source for future manipulation.
我使用 Intervention( http://image.intervention.io/api/make) 来构建 CakePHP 3 图像行为,我想提供从远程服务器轻松上传的功能,并保留原始图像作为未来操作的来源。
EDIT
编辑
I ask,is there the Intervention Imagemethod that returns the name of the file, when taken from the remote server. I know php copy(), I can also use the CakePHP File utilities, but it gives me the duplicate request on remote file.
我问,当从远程服务器获取时,是否有返回文件名的干预图像方法。我知道 php copy(),我也可以使用 CakePHP File 实用程序,但它给了我对远程文件的重复请求。
回答by F. johns
response() does not return the original filename like Salines was requesting. This should work
response() 不会像 Salines 请求的那样返回原始文件名。这应该工作
$path = 'https://i.stack.imgur.com/koFpQ.png';
$filename = basename($path);
Image::make($path)->save(public_path('images/' . $filename));
回答by CDF
You can easily do it using the make();
and response();
methods. Check my code below.
您可以使用make();
和response();
方法轻松完成。在下面检查我的代码。
Just keep in mind that allow_url_fopen
must be enabled to fetch a remote image.
请记住,allow_url_fopen
必须启用才能获取远程图像。
This will display my profile picture. If you are not using it with Laravel Framework, just replace return with echo
.
这将显示我的个人资料图片。如果您没有在Laravel 框架中使用它,只需将 return 替换为echo
.
$img = Image::make('https://i.stack.imgur.com/koFpQ.png');
header('Content-Type: image/png');
return $img->response();
Hope that helps and upvote my reply if useful ;)
希望对我有帮助,如果有用,请给我的回复点赞;)
If you need further help just ask.
如果您需要进一步的帮助,请直接询问。