pnglitch 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -3
- data/README.md +28 -5
- data/lib/pnglitch.rb +1 -1
- data/lib/pnglitch/base.rb +14 -6
- data/spec/pnglitch_spec.rb +0 -38
- metadata +3 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96e25f4174612475f161dbde96789c02ccc9bde007f02b8d0de33e3f35483502
|
4
|
+
data.tar.gz: 5831707ac9afb72b717b7abbab0754d6bae72d791801d74a9dd9aa29bd587cda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28bca69993b3461d5e44abc3351dae3396f73804fb13c32a7385cf08567e1afa23d773f669c4e8352054ccb908c8c922104cad30c243dcb395fd2dc2296431f6
|
7
|
+
data.tar.gz: 7d901fd5d69a55859b75cfc343b7d220f4c4d1752e4bc61762886d90f247746c5786c6139708ee0ea521698d75f0de3a5fcf7dcadf0bf1c18a374af9ade5efdc
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,16 +9,39 @@ With normal data-bending technique, a glitch against PNG will easily fail
|
|
9
9
|
because of the checksum function. We provide a fail-proof destruction for it.
|
10
10
|
Using this library you will see beautiful and various PNG artifacts.
|
11
11
|
|
12
|
+
For more details about glitching PNG image, see
|
13
|
+
[my documentation _The Art of PNG Glitch_](http://ucnv.github.io/pnglitch/).
|
14
|
+
|
12
15
|
## Usage
|
13
16
|
|
14
17
|
```ruby
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
require 'pnglitch'
|
19
|
+
|
20
|
+
PNGlitch.open('/path/to/your/image.png') do |p|
|
21
|
+
p.glitch do |data|
|
22
|
+
data.gsub /\d/, 'x'
|
20
23
|
end
|
24
|
+
p.save '/path/to/broken/image.png'
|
25
|
+
end
|
21
26
|
```
|
27
|
+
|
28
|
+
_The Art of PNG Glitch_ includes [the usage of this library](http://ucnv.github.io/pnglitch/#appendix-a).
|
29
|
+
|
30
|
+
### CLI
|
31
|
+
|
32
|
+
Once you've installed the gem, it can be used in the terminal.
|
33
|
+
|
34
|
+
```sh
|
35
|
+
Usage:
|
36
|
+
pnglitch <infile> [--filter=<n>] <outfile>
|
37
|
+
|
38
|
+
Options:
|
39
|
+
-f, --filter=<n> Fix all filter types as passed value before glitching.
|
40
|
+
A number (0..4) or a type name (none|sub|up|average|paeth).
|
41
|
+
--version Show version.
|
42
|
+
-h, --help Show this screen.
|
43
|
+
```
|
44
|
+
|
22
45
|
## Installation
|
23
46
|
|
24
47
|
Add this line to your application's Gemfile:
|
data/lib/pnglitch.rb
CHANGED
data/lib/pnglitch/base.rb
CHANGED
@@ -20,11 +20,19 @@ module PNGlitch
|
|
20
20
|
@filtered_data = Tempfile.new 'filtered', encoding: 'ascii-8bit'
|
21
21
|
@idat_chunk_size = nil
|
22
22
|
|
23
|
+
@head_data.binmode
|
24
|
+
@tail_data.binmode
|
25
|
+
@compressed_data.binmode
|
26
|
+
@filtered_data.binmode
|
27
|
+
|
23
28
|
open(path, 'rb') do |io|
|
24
29
|
idat_sizes = []
|
25
30
|
@head_data << io.read(8) # signature
|
26
31
|
while bytes = io.read(8)
|
27
32
|
length, type = bytes.unpack 'Na*'
|
33
|
+
if length > io.size - io.pos
|
34
|
+
raise FormatError.new path.to_s
|
35
|
+
end
|
28
36
|
if type == 'IHDR'
|
29
37
|
ihdr = {
|
30
38
|
width: io.read(4).unpack('N').first,
|
@@ -123,7 +131,7 @@ module PNGlitch
|
|
123
131
|
# glitching but some viewer applications might deny to process those results.
|
124
132
|
# To be polite to the filter types, use +each_scanline+ instead.
|
125
133
|
#
|
126
|
-
# Since this method sets the decompressed data into String, it may use a massive amount of
|
134
|
+
# Since this method sets the decompressed data into String, it may use a massive amount of
|
127
135
|
# memory. To decrease the memory usage, treat the data as IO through +glitch_as_io+ instead.
|
128
136
|
#
|
129
137
|
def glitch &block # :yield: data
|
@@ -158,8 +166,8 @@ module PNGlitch
|
|
158
166
|
# To set a glitched result, return the modified value in the block.
|
159
167
|
#
|
160
168
|
# Once the compressed data is glitched, PNGlitch will warn about modifications to
|
161
|
-
# filtered (decompressed) data because this method does not decompress the glitched
|
162
|
-
# compressed data again. It means that calling +glitch+ after +glitch_after_compress+
|
169
|
+
# filtered (decompressed) data because this method does not decompress the glitched
|
170
|
+
# compressed data again. It means that calling +glitch+ after +glitch_after_compress+
|
163
171
|
# will make the result overwritten and forgotten.
|
164
172
|
#
|
165
173
|
# This operation will often destroy PNG image completely.
|
@@ -276,7 +284,7 @@ module PNGlitch
|
|
276
284
|
end
|
277
285
|
|
278
286
|
#
|
279
|
-
# Process each
|
287
|
+
# Process each scanline.
|
280
288
|
#
|
281
289
|
# It takes a block with a parameter. The parameter must be an instance of
|
282
290
|
# PNGlitch::Scanline and it provides ways to edit the filter type and the data
|
@@ -449,7 +457,7 @@ module PNGlitch
|
|
449
457
|
#
|
450
458
|
def save file
|
451
459
|
wrap_with_rewind(@head_data, @tail_data, @compressed_data) do
|
452
|
-
open(file, '
|
460
|
+
open(file, 'wb') do |io|
|
453
461
|
io << @head_data.read
|
454
462
|
chunk_size = @idat_chunk_size || @compressed_data.size
|
455
463
|
type = 'IDAT'
|
@@ -552,7 +560,7 @@ module PNGlitch
|
|
552
560
|
message = <<-EOL.gsub(/^\s*/, '')
|
553
561
|
WARNING: `#{trace.first.label}' is called after a modification to the compressed data.
|
554
562
|
With this operation, your changes on the compressed data will be reverted.
|
555
|
-
Note that a modification to the compressed data does not reflect to the
|
563
|
+
Note that a modification to the compressed data does not reflect to the
|
556
564
|
filtered (decompressed) data.
|
557
565
|
It's happened around #{trace.last.to_s}
|
558
566
|
EOL
|
data/spec/pnglitch_spec.rb
CHANGED
@@ -400,28 +400,6 @@ describe PNGlitch do
|
|
400
400
|
ChunkyPNG::Image.from_file outfile
|
401
401
|
}.not_to raise_error
|
402
402
|
|
403
|
-
if system('which convert > /dev/null')
|
404
|
-
out1 = outdir.join('a.png')
|
405
|
-
out2 = outdir.join('b.png')
|
406
|
-
fx = 4
|
407
|
-
png = PNGlitch.open infile
|
408
|
-
png.each_scanline do |line|
|
409
|
-
line.change_filter fx
|
410
|
-
end
|
411
|
-
png.output out1
|
412
|
-
png.close
|
413
|
-
system('convert -quality %d %s %s' % [fx, infile, out2])
|
414
|
-
png1 = PNGlitch.open out1
|
415
|
-
png2 = PNGlitch.open out2
|
416
|
-
d1 = png1.filtered_data.read
|
417
|
-
d2 = png2.filtered_data.read
|
418
|
-
f1 = png1.filter_types
|
419
|
-
f2 = png2.filter_types
|
420
|
-
png1.close
|
421
|
-
png2.close
|
422
|
-
expect(f1).to eq(f2)
|
423
|
-
expect(d1).to eq(d2)
|
424
|
-
end
|
425
403
|
end
|
426
404
|
|
427
405
|
it 'can change filter type with the name' do
|
@@ -666,22 +644,6 @@ describe PNGlitch do
|
|
666
644
|
end
|
667
645
|
end
|
668
646
|
|
669
|
-
it 'should finalize the instance' do
|
670
|
-
PNGlitch.open infile do
|
671
|
-
lines = scanline_at 1..100
|
672
|
-
end
|
673
|
-
GC.start
|
674
|
-
count = ObjectSpace.each_object(PNGlitch::Scanline).count
|
675
|
-
expect(count).to be < 100
|
676
|
-
|
677
|
-
png = PNGlitch.open infile
|
678
|
-
lines = png.scanline_at 1..100
|
679
|
-
png.close
|
680
|
-
lines = nil
|
681
|
-
GC.start
|
682
|
-
count = ObjectSpace.each_object(PNGlitch::Scanline).count
|
683
|
-
expect(count).to be < 100
|
684
|
-
end
|
685
647
|
end
|
686
648
|
|
687
649
|
describe '.change_all_filters' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pnglitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ucnv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.4.5
|
108
|
+
rubygems_version: 3.0.3
|
110
109
|
signing_key:
|
111
110
|
specification_version: 4
|
112
111
|
summary: PNGlitch is a Ruby library to destroy your PNG images. With normal data-bending
|
@@ -126,4 +125,3 @@ test_files:
|
|
126
125
|
- spec/pnglitch_filter_spec.rb
|
127
126
|
- spec/pnglitch_spec.rb
|
128
127
|
- spec/spec_helper.rb
|
129
|
-
has_rdoc:
|