简体   繁体   English

我怎样才能保存这个php创建的图像?

[英]How can I save this php created image?

What are some possible ways to save an image or make use of it that is generated from a PHP script. 有哪些可能的方法来保存图像或使用从PHP脚本生成的图像。 Using save as it does not help though. 使用save虽然没有帮助。
This is not an image created by me that's why I want to avoid get_contents . 这不是我创建的图像,这就是我想避免get_contents的原因。

here is the picture 这是图片

and here is the url 这是网址

https://render01.fontshop.com/fonts/font_rend.php?idt=f&id=38005&rbe=fsifr&rt=how+do+I+save+this?&rs=38&w=500&bg=ffffff&fg=000000&tp=0.0 https://render01.fontshop.com/fonts/font_rend.php?idt=f&id=38005&rbe=fsifr&rt=how+do+I+save+this?&rs=38&w=500&bg=ffffff&fg=000000&tp=0.0

Using file_put_contents() function. 使用file_put_contents()函数。 If you don't have data in variable and want to readout use file_get_contents() 如果您没有变量中的数据并想要读出使用file_get_contents()

Just write the content of the URL to a file 只需将URL的内容写入文件

<?php
file_put_contents("img.png", file_get_contents("http://render01.fontshop.com/fonts/font_rend.php?idt=f&id=38005&rbe=fsifr&rt=how+do+I+save+this?&rs=38&w=500&bg=ffffff&fg=000000&tp=0.0"));

Since you are not generating the image in your own code, the simplest would be a combo of file_get_contents and file_put_contents : 由于您不是用自己的代码生成图像,因此最简单的方法是file_get_contentsfile_put_contents的组合:

$url = '...'; // your url here
$data = file_get_conents($url);
file_put_conents('image.png', $data);

In this specific case the render is a PNG image, but if there's a possibility of it being a JPEG or something else then you need to somehow detect that as well. 在这种特定情况下,渲染是PNG图像,但是如果有可能是JPEG或其他东西,那么您还需要以某种方式进行检测。 I 'm not giving any suggestions for this because there's not enough info to go by. 我没有给出任何建议,因为没有足够的信息。

use imagepng function. 使用imagepng函数。

It will return file to browser or save it specified location. 它将文件返回到浏览器或保存在指定位置。 Need to set parameter for function to save image on specified location. 需要设置功能参数以将图像保存在指定位置。

您可以在imgpng()或其他函数中定义文件名,以告知PHP存储图片而不是将其发送到调用浏览器。

You can do this from the terminal using the curl command. 您可以使用curl命令从终端执行此操作。

curl -o out.png 'http://render01.fontshop.com/fonts/font_rend.php?idt=f&id=38005&rbe=fsifr&rt=how+do+I+save+this?&rs=38&w=500&bg=ffffff&fg=000000&tp=0.0'

This will save the file as out.png 这会将文件保存为out.png

I understand you want to save it on the client, with a browser, not on the server. 我知道你想用浏览器将它保存在客户端上,而不是在服务器上。

"Save as" worked fine for me (Firefox 7). “另存为”对我来说效果很好(Firefox 7)。 In Chrome you'll have to specify the extension of the filename manually. 在Chrome中,您必须手动指定文件名的扩展名。 Did not test other browsers, but it should work similarly 没有测试其他浏览器,但是应该可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM