pixel-art-export-sizes 0.1.0

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +27 -0
  4. data/lib/pixel_art_export_sizes.rb +30 -0
  5. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f1210251878da4177aba01f6153bd1ac1086dfc4798196fa713ea03d12c27de9
4
+ data.tar.gz: f36d93e325161ee34a859e7dd89f6f6858b35a6d55ed58b338c4af8673f351d0
5
+ SHA512:
6
+ metadata.gz: f17a51c9084b390220dab8c57d189b3ce7e4e6974fa2e4c889e032b6b907db427633e3043edc4236acf125cdda0b664ab632da856f1e2585afce3d866dd7fb55
7
+ data.tar.gz: 54f63024982bcc37d63a8e3765ec2f1e5048fe0aa850524865e5b9d1ee4e07094a5bd544226264916a78007336de91e3b9e64b49a1e4b9c643f6ed44fb05c2db
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 js-upup
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Pixel Art Export Sizes
2
+
3
+ Find whole-number export scales for a sprite or pixel-art canvas. Supply the
4
+ original dimensions and your delivery bounds to get a size that keeps each
5
+ source pixel the same number of pixels wide and tall.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ gem install pixel-art-export-sizes
11
+ ```
12
+
13
+ ```ruby
14
+ require "pixel_art_export_sizes"
15
+
16
+ size = PixelArtExportSizes.largest(
17
+ width: 32, height: 24, min_width: 96, max_width: 160, max_height: 120
18
+ )
19
+ # size.scale is 5, size.width is 160, and size.height is 120.
20
+ ```
21
+
22
+ Use `scale_range` to obtain every fitting integer scale as a Ruby range.
23
+ When no scale fits, `largest` returns `nil`. The library calculates
24
+ dimensions and leaves resampling to your image editor. Ruby 2.6 or newer.
25
+ MIT license.
26
+
27
+ Related workflow at the [PicVane Pixel Art Generator](https://picvane.com/image/ai-pixel-art-generator).
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PixelArtExportSizes
4
+ Size = Struct.new(:scale, :width, :height, keyword_init: true)
5
+
6
+ # Return fitting integer scales, including both endpoints of the range.
7
+ def self.scale_range(width:, height:, min_width: 1, min_height: 1,
8
+ max_width:, max_height:)
9
+ sizes = [width, height, min_width, min_height, max_width, max_height]
10
+ unless sizes.all? { |size| size.is_a?(Integer) && size.positive? }
11
+ raise ArgumentError, "dimensions must be positive integers"
12
+ end
13
+ if min_width > max_width || min_height > max_height
14
+ raise ArgumentError, "minimum dimensions must fit maximum dimensions"
15
+ end
16
+
17
+ low = [(min_width + width - 1) / width, (min_height + height - 1) / height].max
18
+ high = [max_width / width, max_height / height].min
19
+ low..high
20
+ end
21
+
22
+ # Pick the largest legal export, or return nil when the range is empty.
23
+ def self.largest(width:, height:, **limits)
24
+ range = scale_range(width: width, height: height, **limits)
25
+ return nil if range.begin > range.end
26
+
27
+ scale = range.end
28
+ Size.new(scale: scale, width: width * scale, height: height * scale)
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pixel-art-export-sizes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - js-upup
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Calculate fitting integer scales and the largest export dimensions for
14
+ pixel art.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/pixel_art_export_sizes.rb
23
+ homepage: https://picvane.com/image/ai-pixel-art-generator
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '2.6'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.0.3.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Find integer pixel-art export scales within width and height limits.
46
+ test_files: []