如何在 CamanJS 中编辑远程图像

How to edit remote images in CamanJS

文档说

CamanJS comes with a PHP proxy (you're welcome to add a proxy in the language of your choice) that you can use in the proxies folder. Before you use CamanJS for editing, all you have to do to enable the proxy is:

// Will use the PHP proxy in the proxies folder.
Caman.remoteProxy = Caman.IO.useProxy('php');

// You can also specify a URL instead of calling useProxy().
// This will call /proxies/proxy.php?camanProxyUrl={url}
Caman.remoteProxy = "/proxies/proxy.php";

看完之后我写了下面的代码

<script>
Caman.remoteProxy = Caman.IO.useProxy('php');
more javaScript here.
</script>

浏览器怎么会说出于安全原因无法编辑。我写错了吗?我必须在某处包含一个 php 文件吗? PHP 文件在哪里?

您必须在服务器上托管 PHP 脚本(在存储库的 proxies 文件夹中可用),这样它就可以在与服务 CamanJS 的页面完全相同的域中使用。该脚本会将来自远程源的图像数据代理到浏览器,以规避此限制。当然,您并不局限于使用提供的 PHP 脚本。您可以使用任何您想要的 server-side 语言,只要它做同样的事情。

或者,如果您可以控制源,则可以向服务器响应添加 Cross-Origin 资源共享 (CORS) header,这将告诉浏览器可以使用图像尽管域不同。