Module: PSD::Image::Export::PNG

Included in:
PSD::Image
Defined in:
lib/psd/image_exports/png.rb

Overview

PNG image export. This is the default export format.

Instance Method Summary collapse

Instance Method Details

#save_as_png(file) ⇒ Object

Saves the PNG data to disk.



34
35
36
# File 'lib/psd/image_exports/png.rb', line 34

def save_as_png(file)
  to_png.save(file, :fast_rgba)
end

#to_pngObject Also known as: export

Load the image pixels into a PNG file and return a reference to the data.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/psd/image_exports/png.rb', line 9

def to_png
  @png ||= (
    PSD.logger.debug "Beginning PNG export"
    png = ChunkyPNG::Image.new(width.to_i, height.to_i, ChunkyPNG::Color::TRANSPARENT)

    i = 0
    height.times do |y|
      width.times do |x|
        png[x,y] = ChunkyPNG::Color.rgba(
          @pixel_data[i],
          @pixel_data[i+1],
          @pixel_data[i+2],
          @pixel_data[i+3]
        )

        i += 4
      end
    end

    png
  )
end