Sha256: cdbce997a8e23d9577321f4e579bec00d3066b7094057e4be6d96ec3092dee59

Contents?: true

Size: 709 Bytes

Versions: 1

Compression:

Stored size: 709 Bytes

Contents

require 'oily_png'

class PSD::Image
  module Export
    # PNG image export. This is the default export format.
    module PNG
      # Load the image pixels into a PNG file and return a reference to the
      # data.
      def to_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] = @pixel_data[i]
            i += 1
          end
        end

        png
      end
      alias :export :to_png

      # Saves the PNG data to disk.
      def save_as_png(file)
        to_png.save(file, :fast_rgba)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
psd-1.2.0 lib/psd/image_exports/png.rb