Sha256: 0fde32abb0de22202c92df75ebb961da3f3f60a664617a544a5526d305a3c326

Contents?: true

Size: 749 Bytes

Versions: 5

Compression:

Stored size: 749 Bytes

Contents

require RUBY_ENGINE =~ /jruby/ ? 'chunky_png' : '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

5 entries across 5 versions & 1 rubygems

Version Path
psd-1.3.3 lib/psd/image_exports/png.rb
psd-1.3.2 lib/psd/image_exports/png.rb
psd-1.3.0 lib/psd/image_exports/png.rb
psd-1.2.2 lib/psd/image_exports/png.rb
psd-1.2.1 lib/psd/image_exports/png.rb