dreamega-ico-encoder 1.0.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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/lib/dreamega/ico_encoder.rb +46 -0
- data/lib/dreamega-ico-encoder.rb +1 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d4345524ff4b6e7884c49fe13bffbd43c9f9d457e98d079c8ad0439c0be1bb8e
|
|
4
|
+
data.tar.gz: bcd895c3326b63bae6da60d7ecb76f46db256aae0184da9247ab3b6b836df8f0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e644bea1d797a0c0e329ede2bd83c670ba851da387e8e9d2d864821f41e5fd8e4f55df4ab4bca29f8ba3ff8b7715d515cde7d0aac2ae4811a6d4936ff70299de
|
|
7
|
+
data.tar.gz: b3b39c8c27814e160f887f3ef271bca3ab76f5b681aee5d9b5ab5bdb160622ce616b9ea2322e6d53e2040cc6484672d4aa64740df7ef2c43553247d4081efe9f
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dreamega
|
|
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,39 @@
|
|
|
1
|
+
# dreamega-ico-encoder
|
|
2
|
+
|
|
3
|
+
Generate multi-size ICO favicon files from PNG images in pure Ruby.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem install dreamega-ico-encoder
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or add to your Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem "dreamega-ico-encoder"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require "dreamega-ico-encoder"
|
|
21
|
+
|
|
22
|
+
# Build a hash of size => PNG binary data
|
|
23
|
+
png_images = {
|
|
24
|
+
16 => File.binread("icon-16.png"),
|
|
25
|
+
32 => File.binread("icon-32.png"),
|
|
26
|
+
64 => File.binread("icon-64.png"),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
ico_data = Dreamega::IcoEncoder.generate(png_images)
|
|
30
|
+
File.binwrite("favicon.ico", ico_data)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Links
|
|
34
|
+
|
|
35
|
+
- Homepage: [https://dreamega.ai](https://dreamega.ai)
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Dreamega
|
|
2
|
+
module IcoEncoder
|
|
3
|
+
# Default icon sizes for ICO generation.
|
|
4
|
+
DEFAULT_SIZES = [16, 32, 48, 64, 128, 256].freeze
|
|
5
|
+
|
|
6
|
+
# Generate an ICO file from a hash of {size => png_bytes}.
|
|
7
|
+
#
|
|
8
|
+
# @param png_images [Hash<Integer, String>] mapping of pixel size to PNG binary data
|
|
9
|
+
# @return [String] ICO file binary string
|
|
10
|
+
def self.generate(png_images)
|
|
11
|
+
entries = png_images.sort_by { |size, _| size }
|
|
12
|
+
count = entries.length
|
|
13
|
+
|
|
14
|
+
# ICO header (6 bytes): reserved, type=1 (ICO), image count
|
|
15
|
+
header = [0, 1, count].pack("v3")
|
|
16
|
+
|
|
17
|
+
# Calculate offset where image data starts
|
|
18
|
+
# Header (6) + directory entries (16 * count)
|
|
19
|
+
data_offset_base = 6 + 16 * count
|
|
20
|
+
current_offset = data_offset_base
|
|
21
|
+
|
|
22
|
+
directory = "".b
|
|
23
|
+
image_data = "".b
|
|
24
|
+
|
|
25
|
+
entries.each do |size, png_data|
|
|
26
|
+
png_bytes = png_data.b
|
|
27
|
+
w = size >= 256 ? 0 : size
|
|
28
|
+
h = w
|
|
29
|
+
|
|
30
|
+
# Directory entry (16 bytes):
|
|
31
|
+
# width, height, color_count, reserved (each 1 byte)
|
|
32
|
+
# color_planes (2 bytes), bits_per_pixel (2 bytes)
|
|
33
|
+
# data_size (4 bytes), data_offset (4 bytes)
|
|
34
|
+
entry = [w, h, 0, 0].pack("C4")
|
|
35
|
+
entry += [1, 32].pack("v2")
|
|
36
|
+
entry += [png_bytes.length, current_offset].pack("V2")
|
|
37
|
+
|
|
38
|
+
directory += entry
|
|
39
|
+
image_data += png_bytes
|
|
40
|
+
current_offset += png_bytes.length
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
header + directory + image_data
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative "dreamega/ico_encoder"
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dreamega-ico-encoder
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dreamega
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-04-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A pure Ruby library for generating ICO favicon files. Supports multiple
|
|
14
|
+
image sizes with proper ICO binary format headers.
|
|
15
|
+
email:
|
|
16
|
+
- dev@dreamega.ai
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/dreamega-ico-encoder.rb
|
|
24
|
+
- lib/dreamega/ico_encoder.rb
|
|
25
|
+
homepage: https://dreamega.ai
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/dreamega-ai/dreamega-ico-encoder-ruby
|
|
30
|
+
homepage_uri: https://dreamega.ai
|
|
31
|
+
post_install_message:
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 2.7.0
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements: []
|
|
46
|
+
rubygems_version: 3.0.3.1
|
|
47
|
+
signing_key:
|
|
48
|
+
specification_version: 4
|
|
49
|
+
summary: Generate multi-size ICO favicon files from PNG images
|
|
50
|
+
test_files: []
|