pixelart 1.3.3 → 1.3.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0724e3e1f83da6ef84325d79706a2f59d773eb31478f1e4d797ff582dad64a4a
4
- data.tar.gz: 7d75ebe3aef0abb3e3d142bf787995bbcdf797416912a387601110a3547d08fe
3
+ metadata.gz: 92c0d22468eb46c7120b5cdfeeca63f0d4049bdfc055037186e05690e81f3404
4
+ data.tar.gz: 1d5cb926059539d9bce964243a099307e1c03de5be9de7c5285bc76d54acb7cb
5
5
  SHA512:
6
- metadata.gz: 6afe87fa92ec1de03bad71cd5f2ba298f78287b77f514a6c74cae6747c1e1d62790d722c07fb0a5d049dcf9966d4fa0a473688e71c717de534420f4746b711f2
7
- data.tar.gz: 0b1a7cf13cdffa7410a6c0246f894d3ca5f1e3b1347fd90b9f7cbe9ed3cff4b4fc87c6704d80854b5337aa5f17e24631c28bc8188e4c6f86422e862d22949d43
6
+ metadata.gz: 17a632b18859b6c341e5d80ecc91bdacff31037c3067efcda244d722515e70f8689613dbc205ed0e43300fdb5e5e36da70e079287adf7b4775041ca6ed3d1653
7
+ data.tar.gz: 8fe33b806a59f408ce6666de365e13023175f87314b832cad3f196dc96f4c83aee37013ab554e30e015e2df621047a28091937506b03df1f09deef10773dc5e3
data/Manifest.txt CHANGED
@@ -7,6 +7,7 @@ lib/pixelart/base.rb
7
7
  lib/pixelart/blur.rb
8
8
  lib/pixelart/circle.rb
9
9
  lib/pixelart/composite.rb
10
+ lib/pixelart/convert.rb
10
11
  lib/pixelart/generator.rb
11
12
  lib/pixelart/image.rb
12
13
  lib/pixelart/led.rb
data/Rakefile CHANGED
@@ -18,10 +18,10 @@ Hoe.spec 'pixelart' do
18
18
  self.history_file = 'CHANGELOG.md'
19
19
 
20
20
  self.extra_deps = [
21
+ ['cocos'],
21
22
  ['pixelart-colors'],
22
23
  ['chunky_png'],
23
24
  ['mini_magick'],
24
- ['csvreader'],
25
25
  ]
26
26
 
27
27
  self.licenses = ['Public Domain']
data/lib/pixelart/base.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'cocos'
2
+ require 'base64'
3
+
4
+
1
5
  ###
2
6
  # base module
3
7
  require 'pixelart/colors'
@@ -13,10 +17,6 @@ require 'chunky_png'
13
17
  require 'mini_magick'
14
18
 
15
19
 
16
- # bonus / prologue / convenience 3rd party
17
- require 'csvreader'
18
-
19
-
20
20
 
21
21
  ## our own code
22
22
  require 'pixelart/version' # note: let version always go first
@@ -63,6 +63,10 @@ require 'pixelart/blur'
63
63
 
64
64
 
65
65
 
66
+ ###
67
+ # mover helpers / utils
68
+ require 'pixelart/convert'
69
+
66
70
 
67
71
 
68
72
  puts Pixelart.banner # say hello
@@ -0,0 +1,54 @@
1
+ module Pixelart
2
+
3
+ class Image
4
+
5
+
6
+ ## helper to convert (all) image in directory
7
+ ## chech: move to ImageUtils.convert or such - why? why not?
8
+ ##
9
+ ## what about the name e.g. rename to convert_dir or
10
+ ## batch_convert such - why? why not?
11
+ def self.convert( dir, from: 'jpg',
12
+ to: 'png',
13
+ outdir: nil,
14
+ overwrite: true )
15
+
16
+ outdir = dir if outdir.nil?
17
+
18
+ files = Dir.glob( "#{dir}/*.#{from}" )
19
+ puts "==> found #{files.size} image(s) to convert from #{from} to #{to} (overwrite mode set to: #{overwrite})"
20
+
21
+ files.each_with_index do |file,i|
22
+ dirname = File.dirname( file )
23
+ extname = File.extname( file )
24
+ basename = File.basename( file, extname )
25
+
26
+ ## skip convert if target / dest file already exists
27
+ next if overwrite == false && File.exist?( "#{outdir}/#{basename}.#{to}" )
28
+
29
+ ## note: make sure outdir exists (magic will not create it??)
30
+ FileUtils.mkdir_p( outdir ) unless Dir.exist?( outdir )
31
+
32
+ cmd = "magick convert #{dirname}/#{basename}.#{from} #{outdir}/#{basename}.#{to}"
33
+
34
+ puts " [#{i+1}/#{files.size}] - #{cmd}"
35
+ ## todo/fix: check return value!!! magick comand not available (in path) and so on!!!
36
+ system( cmd )
37
+
38
+ if from == 'gif'
39
+ ## assume multi-images for gif
40
+ ## save image-0.png to image.png
41
+ path0 = "#{outdir}/#{basename}-0.#{to}"
42
+ path = "#{outdir}/#{basename}.#{to}"
43
+
44
+ puts " saving #{path0} to #{path}..."
45
+
46
+ blob = File.open( path0, 'rb' ) { |f| f.read }
47
+ File.open( path, 'wb' ) { |f| f.write( blob ) }
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ end # class Image
54
+ end # class Pixelart
@@ -2,12 +2,49 @@ module Pixelart
2
2
 
3
3
  class Image
4
4
 
5
+
6
+ ## keep track of all (inherited) subclasses via inherited hook
7
+ ##
8
+ ## change/rename to descendants - why? why not?
9
+ ##
10
+ ## note about rails (activesupport?)
11
+ ## If you use rails >= 3, you have two options in place.
12
+ ## Use .descendants if you want more than one level depth of children classes,
13
+ ## or use .subclasses for the first level of child classes.
14
+
15
+ def self.subclasses
16
+ @subclasses ||= []
17
+ end
18
+
19
+ def self.inherited( subclass )
20
+ subclasses << subclass
21
+ end
22
+
23
+
24
+
25
+
5
26
  def self.read( path ) ## convenience helper
6
27
  img_inner = ChunkyPNG::Image.from_file( path )
7
- img = new( img_inner.width, img_inner.height, img_inner )
8
- img
28
+ new( img_inner.width, img_inner.height, img_inner )
29
+ end
30
+
31
+ def self.parse_base64( str )
32
+ blob = Base64.decode64( str )
33
+ img_inner = ChunkyPNG::Image.from_blob( blob )
34
+ new( img_inner.width, img_inner.height, img_inner )
9
35
  end
10
36
 
37
+ def self.blob( blob )
38
+ img_inner = ChunkyPNG::Image.from_blob( blob )
39
+ new( img_inner.width, img_inner.height, img_inner )
40
+ end
41
+
42
+ class << self
43
+ alias_method :from_blob, :blob
44
+ end
45
+
46
+
47
+
11
48
 
12
49
 
13
50
  CHARS = '.@xo^~%*+=:' ## todo/check: rename to default chars or such? why? why not?
@@ -95,6 +132,19 @@ def crop( x, y, crop_width, crop_height )
95
132
  end
96
133
 
97
134
 
135
+ ## shift image n-pixels to the left (NOT changing width/height)
136
+ def left( left )
137
+ img = Image.new( width, height )
138
+ img.compose!( crop( 0, 0, width-left, height ), left, 0 )
139
+ img
140
+ end
141
+
142
+
143
+ def to_blob
144
+ @img.to_blob
145
+ end
146
+ alias_method :blob, :to_blob
147
+
98
148
 
99
149
  #######################
100
150
  ## filter / effects
@@ -106,19 +156,35 @@ end
106
156
  alias_method :greyscale, :grayscale
107
157
 
108
158
 
109
-
110
- def flip
111
- img = @img.flip
159
+ ######################
160
+ # flip horizontally on x-axis (top-to-bottom/bottom-to-top)
161
+ # e.g. pixels on the top will now be pixels on the bottom
162
+ #
163
+ # todo/check: commom use is reverse?
164
+ # e.g. flip_vertically is top-to-bottom!!!
165
+ # use flip_y_axis, flip_x_axis or something else - why? why not?
166
+ # check photoshop and gimp terminology and update later if different - why? why not?
167
+ def flip_horizontally
168
+ img = @img.flip_horizontally
112
169
  Image.new( img.width, img.height, img )
113
170
  end
114
- alias_method :flip_horizontally, :flip
171
+ ## keep flop? alias - why? why not?
172
+ ## note: chunky_png use flip alias for flip_horizontally!!!!
173
+ alias_method :flop, :flip_horizontally
174
+
175
+
115
176
 
177
+ ###
178
+ # flip vertially on y-axis (right-to-left/left-to-right)
179
+ # e.g. pixels on the left will now be pixels on the right
116
180
  def mirror
117
181
  img = @img.mirror
118
182
  Image.new( img.width, img.height, img )
119
183
  end
120
184
  alias_method :flip_vertically, :mirror
121
- alias_method :flop, :mirror
185
+ alias_method :flip, :mirror ## note: chunky_png use flip alias for flip_horizontally (top-to-bottom)!!!!
186
+ alias_method :phlip, :mirror ## philip the intern ("hand-phlip one-by-one")
187
+ alias_method :hand_phlip, :mirror
122
188
 
123
189
 
124
190
  def rotate_counter_clockwise # 90 degrees
@@ -3,7 +3,7 @@ module Pixelart
3
3
 
4
4
  MAJOR = 1
5
5
  MINOR = 3
6
- PATCH = 3
6
+ PATCH = 6
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelart
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-09 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: pixelart-colors
14
+ name: cocos
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: chunky_png
28
+ name: pixelart-colors
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mini_magick
42
+ name: chunky_png
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: csvreader
56
+ name: mini_magick
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -119,6 +119,7 @@ files:
119
119
  - lib/pixelart/blur.rb
120
120
  - lib/pixelart/circle.rb
121
121
  - lib/pixelart/composite.rb
122
+ - lib/pixelart/convert.rb
122
123
  - lib/pixelart/generator.rb
123
124
  - lib/pixelart/image.rb
124
125
  - lib/pixelart/led.rb