实现这种图像效果的最佳方法是什么?使用 PHP GD 还是 JS Canvas?
我正在尝试重新创建这种效果(皇冠):
用户上传图像的位置暗像素为黑色,亮像素为透明。这是一个好方法吗?
我还发现了这一点: 如何你用 PHP 将图像转换为黑白
但我不太确定如何实现它。
人们会为此推荐 JS Canvas 还是 PHP 的 GD?
我不会每次都一遍又一遍地创建图像,我会处理它并将其移动到目录以供将来使用
I'm trying to recreate this effect (the crown):
Where the user uploads an image and it turns the dark pixels black and the light pixels clear. Would this be a good method?
I also spotted this on SO: How do you convert an image to black and white in PHP
But i'm not really sure how to implement it.
Would people recommend JS Canvas for this or PHP's GD?
I wouldnt be creating the images over and over each time, i would process it and move it to a directory for future use
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是在 JS 中的实现方法。请注意,图像必须来自同一域才能正常工作:
我使用虚拟 ID 来向您展示事情是如何工作的。另外,请查看此页面,了解有关像素操作的更多信息。
也就是说,这需要画布才能工作,因此旧版 IE 不支持它(除非您使用 Google 的替换画布,但我不确定它是否支持所有这些方法)。优点是它把负担放在每个用户身上,而不是所有用户的服务器上。
The following is how to do it in JS. Note that the image must be from the same domain to work properly:
I've used dummy ID's to show you how things work. Also, check out this page for more information about pixel manipulation.
That said, this requires canvas to work so it won't be supported in older IE (unless you use Google's replacement canvas, but I'm not sure about its support for all of these methods). The advantage is that it puts the burden on each user instead of on your server for all users.
我建议您使用 raphaeljs 进行绘图,对于像皇冠这样的物体,您可以绘制它们,也可以使用图像。用这个制作 2 位图像也会更容易!
I would suggest you to use raphaeljs for drawing, for objects like crown you can either draw them or you can use images. It also would be easier to make a 2bit image with this!