【发布时间】:2015-10-05 07:24:44
【问题描述】:
我知道如何将图像从数据 uri 加载到结构 js 中。但是如果数据 uri 来自另一个 url,我无法弄清楚如何加载图像。我有一个接受图像 URL 并返回 base64 图像数据的 PHP 脚本。
<?php
$path = $_REQUEST['url'];
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo $base64;
?>
假设网址是http://example.com/encodeImage.php?url=http://example.com/image.png。我正在尝试将此 URL 用于此功能
fabric.Image.fromURL('http://example.com/encodeImage.php?url=http://example.com/image.png', function(img) {
但它无法加载图像。在控制台中显示unable to load the image
有没有可能用fabric js做点什么?
【问题讨论】:
标签: javascript php canvas html5-canvas fabricjs