OSDN Git Service

Regular updates
[twpd/master.git] / chunky_png.md
1 ---
2 title: Chunky PNG
3 category: Ruby libraries
4 layout: 2017/sheet
5 ---
6
7 ### Loading
8
9 ```ruby
10 image = ChunkyPNG::Image.from_file('file.png')
11 ```
12
13 #### Alternate ways
14
15 ```ruby
16 image = ChunkyPNG::Image.from_blob(File.read('file.png'))
17 image = ChunkyPNG::Image.from_io(io) 
18 ```
19
20 Loads from `file.png`.
21
22 ### Saving
23
24 ```ruby
25 image.save('filename.png')
26 ```
27
28 #### Alternate ways
29
30 ```ruby
31 File.open('newfile.png', 'wb') { |io| image.write(io) }
32 binary_string = image.to_blob
33 ```
34
35 Writes an image to `newfile.png`.
36
37 ### Drawing
38
39 ```ruby
40 image[0, 0] = ChunkyPNG::Color.rgba(255, 0,0, 128)
41 image.line(1, 1, 10, 1, ChunkyPNG::Color.from_hex('#aa007f'))
42 ```
43
44 ### Canvas
45
46 ```ruby
47 crop(x, y, w, h)
48 ```
49
50 ### Transforms
51
52 ```ruby
53 new_image = image.flip_horizontally.rotate_right
54 ```