最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I display a pgmppm file in html? - Stack Overflow

programmeradmin2浏览0评论

I have a simple pgm file, which I think is the same as a ppm file.

P3

5 5
10

1 2 3 4 10
1 10 3 2 5
10 2 4 2 1
0 0 0 0 0
10 10 10 10 10

I want to display this file in an HTML document. Right now I have tried using the img tag and an iframe. I want this to display the actual image and not the text. I would like it to be HTML but I can also use javascript.

I have a simple pgm file, which I think is the same as a ppm file.

P3

5 5
10

1 2 3 4 10
1 10 3 2 5
10 2 4 2 1
0 0 0 0 0
10 10 10 10 10

I want to display this file in an HTML document. Right now I have tried using the img tag and an iframe. I want this to display the actual image and not the text. I would like it to be HTML but I can also use javascript.

Share asked Oct 18, 2016 at 16:39 Preston HagerPreston Hager 1,6291 gold badge20 silver badges37 bronze badges 1
  • Please look at the question I have already stated both of these but here they are again. I have tried using an img and iframe tag. I want it to display a pgm image if you need more info on this look here. – Preston Hager Commented Oct 18, 2016 at 18:37
Add a ment  | 

2 Answers 2

Reset to default 2

You'll first need to read the contents of the pgm/ppm file. Then loop through the pixel data of the PPM file, which should already have the RGB values. Then you could use putImageData on the html5 canvas context.

Canvas Pixel Manipulation Examples

https://developer.mozilla/en-US/docs/Web/API/Canvas_API/Tutorial/Pixel_manipulation_with_canvas

PBM/PPM/PGB Format Specs

https://en.wikipedia/wiki/Netpbm_format

Use the canvas element <canvas> and the canvas API. You can use a 1x1 rectangle to draw pixel by pixel.

See https://developer.mozilla/en-US/docs/Web/API/Canvas_API for a starting documentation.

发布评论

评论列表(0)

  1. 暂无评论