Class: AppInfo::PngUncrush

Inherits:
Object
  • Object
show all
Defined in:
lib/app_info/png_uncrush.rb

Overview

Decompress iOS Png image file.

See Also:

Author:

  • Wenwei Cai

Defined Under Namespace

Classes: FormatError, PngReader

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ PngUncrush

Returns a new instance of PngUncrush.

Raises:



85
86
87
88
# File 'lib/app_info/png_uncrush.rb', line 85

def initialize(filename)
  @io = PngReader.new(::File.open(filename))
  raise FormatError, 'not a png file' unless @io.png?
end

Class Method Details

.decompress(input, output) ⇒ Boolean

Decompress crushed png file.

Parameters:

  • input (String)

    path of png file

  • output (String)

    path of output file

Returns:

  • (Boolean)

    result whether decompress successfully



74
75
76
# File 'lib/app_info/png_uncrush.rb', line 74

def self.decompress(input, output)
  new(input).decompress(output)
end

.dimensions(input) ⇒ Array<Integer>

get png dimensions

Parameters:

  • input (String)

    path of png file

Returns:

  • (Array<Integer>)

    dimensions width, height value of png file



81
82
83
# File 'lib/app_info/png_uncrush.rb', line 81

def self.dimensions(input)
  new(input).dimensions
end

Instance Method Details

#decompress(output) ⇒ Boolean

Decompress crushed png file.

Parameters:

  • output (String)

    path of output file

Returns:

  • (Boolean)

    result whether decompress successfully



100
101
102
103
104
105
106
107
108
# File 'lib/app_info/png_uncrush.rb', line 100

def decompress(output)
  content = _remap(_dump_sections)
  return false unless content

  write_file(output, content)
rescue Zlib::DataError
  # perhops thi is a normal png image file
  false
end

#dimensionsArray<Integer>

get png dimensions

Parameters:

  • input (String)

    path of png file

Returns:

  • (Array<Integer>)

    dimensions width, height value of png file



93
94
95
# File 'lib/app_info/png_uncrush.rb', line 93

def dimensions
  _dump_sections(dimensions: true)
end