[英]base 64 og:image to facebook share
我正在使用此库将HTML转换为画布。 然后,我使用以下代码从画布上获取图像:
canvas = document.getElementsByTagName('canvas')[0] context = canvas.getContext('2d') image = new Image() image.src = canvas.toDataURL("image/png")
结果,我得到了base64图像。 在Facebook上分享帖子时,我需要使用此图像。 我知道我需要添加一个元标记og:image
并将og:image
插入那里。 但是它不想接受base64图像。 谁能建议我该怎么做?
请帮忙,谢谢。
我以这种方式解决了这个问题:
首先,我将HTML转换为画布,然后将画布转换为图像,然后使用画布绘制此图像,以裁剪初始图像以消除多余的空间。 完成此操作后,图像将发送到服务器进行存储,并通过og:image元标记传递到FB。
$scope.facebookShared = () ->
$window.open "//www.facebook.com/sharer/sharer.php?u=" + encodeURI($location.absUrl()), "sharer", "toolbar=0,status=0,width=" + 500 + ",height=" + 500 /// this is window for share fb
height=$('.sharing').height()
html2canvas document.body,
onrendered: (canvas) ->
context = canvas.getContext('2d')
image = new Image()
image.src = canvas.toDataURL("image/png")
image.onload = ->
sharing=$('.sharing')
canvas.height = Math.round(sharing.width()/1.91)
canvas.width = sharing.width()
context=canvas.getContext('2d')
pos = sharing.parent(0).parent(0).position()
context.drawImage(this, pos.left, pos.top, sharing.width() + 20, sharing.height(),0,0,sharing.width()+20,sharing.height())
$.ajax
url: '../../save_img'
type: 'post'
beforeSend: (xhr) ->
xhr.setRequestHeader "X-CSRF-Token", $("meta[name=\"csrf-token\"]").attr("content")
return
data:
base64_image: canvas.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/, "")
claim_slug: $scope.claim.slug
return false
width: $('.claim-page ').width()
height: height+115
return
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.