summaryrefslogtreecommitdiff
path: root/devdocs/go/image%2Fpng%2Findex.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/go/image%2Fpng%2Findex.html')
-rw-r--r--devdocs/go/image%2Fpng%2Findex.html104
1 files changed, 104 insertions, 0 deletions
diff --git a/devdocs/go/image%2Fpng%2Findex.html b/devdocs/go/image%2Fpng%2Findex.html
new file mode 100644
index 00000000..81d127b6
--- /dev/null
+++ b/devdocs/go/image%2Fpng%2Findex.html
@@ -0,0 +1,104 @@
+<h1> Package png </h1> <ul id="short-nav">
+<li><code>import "image/png"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package png implements a PNG image decoder and encoder. </p>
+<p>The PNG specification is at <a href="https://www.w3.org/TR/PNG/">https://www.w3.org/TR/PNG/</a>. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#Decode">func Decode(r io.Reader) (image.Image, error)</a></li>
+<li><a href="#DecodeConfig">func DecodeConfig(r io.Reader) (image.Config, error)</a></li>
+<li><a href="#Encode">func Encode(w io.Writer, m image.Image) error</a></li>
+<li><a href="#CompressionLevel">type CompressionLevel</a></li>
+<li><a href="#Encoder">type Encoder</a></li>
+<li> <a href="#Encoder.Encode">func (enc *Encoder) Encode(w io.Writer, m image.Image) error</a>
+</li>
+<li><a href="#EncoderBuffer">type EncoderBuffer</a></li>
+<li><a href="#EncoderBufferPool">type EncoderBufferPool</a></li>
+<li><a href="#FormatError">type FormatError</a></li>
+<li> <a href="#FormatError.Error">func (e FormatError) Error() string</a>
+</li>
+<li><a href="#UnsupportedError">type UnsupportedError</a></li>
+<li> <a href="#UnsupportedError.Error">func (e UnsupportedError) Error() string</a>
+</li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_Decode">Decode</a></dd> <dd><a class="exampleLink" href="#example_Encode">Encode</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>paeth.go</span> <span>reader.go</span> <span>writer.go</span> </p> <h2 id="Decode">func <span>Decode</span> </h2> <pre data-language="go">func Decode(r io.Reader) (image.Image, error)</pre> <p>Decode reads a PNG image from r and returns it as an <span>image.Image</span>. The type of Image returned depends on the PNG contents. </p> <h4 id="example_Decode"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+// This example uses png.Decode which can only decode PNG images.
+// Consider using the general image.Decode as it can sniff and decode any registered image format.
+img, err := png.Decode(gopherPNG())
+if err != nil {
+ log.Fatal(err)
+}
+
+levels := []string{" ", "░", "▒", "▓", "█"}
+
+for y := img.Bounds().Min.Y; y &lt; img.Bounds().Max.Y; y++ {
+ for x := img.Bounds().Min.X; x &lt; img.Bounds().Max.X; x++ {
+ c := color.GrayModel.Convert(img.At(x, y)).(color.Gray)
+ level := c.Y / 51 // 51 * 5 = 255
+ if level == 5 {
+ level--
+ }
+ fmt.Print(levels[level])
+ }
+ fmt.Print("\n")
+}
+</pre> <h2 id="DecodeConfig">func <span>DecodeConfig</span> </h2> <pre data-language="go">func DecodeConfig(r io.Reader) (image.Config, error)</pre> <p>DecodeConfig returns the color model and dimensions of a PNG image without decoding the entire image. </p>
+<h2 id="Encode">func <span>Encode</span> </h2> <pre data-language="go">func Encode(w io.Writer, m image.Image) error</pre> <p>Encode writes the Image m to w in PNG format. Any Image may be encoded, but images that are not <span>image.NRGBA</span> might be encoded lossily. </p> <h4 id="example_Encode"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+const width, height = 256, 256
+
+// Create a colored image of the given width and height.
+img := image.NewNRGBA(image.Rect(0, 0, width, height))
+
+for y := 0; y &lt; height; y++ {
+ for x := 0; x &lt; width; x++ {
+ img.Set(x, y, color.NRGBA{
+ R: uint8((x + y) &amp; 255),
+ G: uint8((x + y) &lt;&lt; 1 &amp; 255),
+ B: uint8((x + y) &lt;&lt; 2 &amp; 255),
+ A: 255,
+ })
+ }
+}
+
+f, err := os.Create("image.png")
+if err != nil {
+ log.Fatal(err)
+}
+
+if err := png.Encode(f, img); err != nil {
+ f.Close()
+ log.Fatal(err)
+}
+
+if err := f.Close(); err != nil {
+ log.Fatal(err)
+}
+</pre> <h2 id="CompressionLevel">type <span>CompressionLevel</span> <span title="Added in Go 1.4">1.4</span> </h2> <p>CompressionLevel indicates the compression level. </p>
+<pre data-language="go">type CompressionLevel int</pre> <pre data-language="go">const (
+ DefaultCompression CompressionLevel = 0
+ NoCompression CompressionLevel = -1
+ BestSpeed CompressionLevel = -2
+ BestCompression CompressionLevel = -3
+)</pre> <h2 id="Encoder">type <span>Encoder</span> <span title="Added in Go 1.4">1.4</span> </h2> <p>Encoder configures encoding PNG images. </p>
+<pre data-language="go">type Encoder struct {
+ CompressionLevel CompressionLevel
+
+ // BufferPool optionally specifies a buffer pool to get temporary
+ // EncoderBuffers when encoding an image.
+ BufferPool EncoderBufferPool // Go 1.9
+}
+</pre> <h3 id="Encoder.Encode">func (*Encoder) <span>Encode</span> <span title="Added in Go 1.4">1.4</span> </h3> <pre data-language="go">func (enc *Encoder) Encode(w io.Writer, m image.Image) error</pre> <p>Encode writes the Image m to w in PNG format. </p>
+<h2 id="EncoderBuffer">type <span>EncoderBuffer</span> <span title="Added in Go 1.9">1.9</span> </h2> <p>EncoderBuffer holds the buffers used for encoding PNG images. </p>
+<pre data-language="go">type EncoderBuffer encoder</pre> <h2 id="EncoderBufferPool">type <span>EncoderBufferPool</span> <span title="Added in Go 1.9">1.9</span> </h2> <p>EncoderBufferPool is an interface for getting and returning temporary instances of the <a href="#EncoderBuffer">EncoderBuffer</a> struct. This can be used to reuse buffers when encoding multiple images. </p>
+<pre data-language="go">type EncoderBufferPool interface {
+ Get() *EncoderBuffer
+ Put(*EncoderBuffer)
+}</pre> <h2 id="FormatError">type <span>FormatError</span> </h2> <p>A FormatError reports that the input is not a valid PNG. </p>
+<pre data-language="go">type FormatError string</pre> <h3 id="FormatError.Error">func (FormatError) <span>Error</span> </h3> <pre data-language="go">func (e FormatError) Error() string</pre> <h2 id="UnsupportedError">type <span>UnsupportedError</span> </h2> <p>An UnsupportedError reports that the input uses a valid but unimplemented PNG feature. </p>
+<pre data-language="go">type UnsupportedError string</pre> <h3 id="UnsupportedError.Error">func (UnsupportedError) <span>Error</span> </h3> <pre data-language="go">func (e UnsupportedError) Error() string</pre><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/image/png/" class="_attribution-link">http://golang.org/pkg/image/png/</a>
+ </p>
+</div>