pura-image 0.2.2 → 0.2.5

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: 4ca9e140b2d7fe143248deaf1eea3d18264a45d0dc7bee03aa1548d20c78f1f7
4
- data.tar.gz: 4a1e12756cf11641681ba7c3d9fad052b26743d343932c0f8270377d7d35647e
3
+ metadata.gz: 5349acbd820a01a5adce41d49add96c50a8e91adc2555629e62268c0876531a5
4
+ data.tar.gz: 293af000448458dbb3554cf203b0eeccc8432516a768116cb7dab56a3a9a3472
5
5
  SHA512:
6
- metadata.gz: 559a878030a06ce938cb386d0635cb6f5bc308606609fe0ff5de560ba14c9d2388c3788be425e13c767a1db40f4ec58eb616234f1825298f012befe38d5ea75b
7
- data.tar.gz: ff0728e7ad559949670393bc0085563a29b2195ab66f0761d3ecae4ea5d021d82d8dee51018fb31d1935c17ae5c6aa122735268689bd077d8c21bfda94fd28fc
6
+ metadata.gz: 06aca37f6a3f060428b1f61dc62ceb39b073b71b7b5f8c3337d451bdc1aa0e95bd3c5b6ffb2a4f9cd610ec73f6e51bf55cadbaa61b1f7a016a705173d2f97bfd
7
+ data.tar.gz: 1864fdfa00abf7767c15c755a4d89211639695448192a0cee09b487029ebefd8096b4fb95d00d9c88de776c44f24ba900060a918c0f18344717b489c6b8594df
data/README.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  Pure Ruby image processing library with **zero C extension dependencies**. Bundles all **pura-*** format gems and provides an `ImageProcessing` adapter for Rails Active Storage.
4
4
 
5
+ ## Why this exists (in 30 seconds)
6
+
7
+ Stop installing system libraries just to resize an image in Rails.
8
+
9
+ ```diff
10
+ # Gemfile
11
+ gem "image_processing"
12
+ + gem "pura-image"
13
+ ```
14
+
15
+ ```ruby
16
+ # config/application.rb
17
+ config.active_storage.variant_processor = :pura
18
+ ```
19
+
20
+ ```diff
21
+ # Dockerfile
22
+ - RUN apt-get install -y libvips-dev imagemagick
23
+ ```
24
+
25
+ That's it. No `brew install vips`. No `apt install imagemagick`. No C compiler. Works on macOS, Linux, Windows, Docker, CI, ruby.wasm — anywhere Ruby runs.
26
+
27
+ - ✅ **Drop-in** for `ImageProcessing::Vips` / `ImageProcessing::MiniMagick`
28
+ - ✅ **7 formats** — JPEG, PNG, BMP, GIF, TIFF, ICO/CUR, WebP
29
+ - ✅ **Some operations are faster than C** (no process-spawn overhead — see [Benchmark](#benchmark))
30
+ - ✅ **Runs on ruby.wasm, JRuby, TruffleRuby**
31
+
5
32
  ## Supported Formats
6
33
 
7
34
  | Format | Decode | Encode | Gem |
@@ -29,7 +56,7 @@ require "pura-image"
29
56
 
30
57
  # Load any format (auto-detected from magic bytes)
31
58
  image = Pura::Image.load("photo.jpg")
32
- image = Pura::Image.load("icon.webp")
59
+ image = Pura::Image.load("logo.png")
33
60
  image.width #=> 800
34
61
  image.height #=> 600
35
62
 
@@ -132,7 +159,6 @@ ImageProcessing::Pura.valid_image?("photo.jpg") #=> true
132
159
  | BMP | **39 ms** | 59 ms | 🚀 **1.5× faster** |
133
160
  | GIF | 77 ms | 65 ms | ~1× (comparable) |
134
161
  | PNG | 111 ms | 60 ms | 1.9× slower |
135
- | WebP | 207 ms | 66 ms | 3.1× slower |
136
162
  | JPEG | 304 ms | 55 ms | 5.5× slower |
137
163
 
138
164
  ### Encode
@@ -19,7 +19,7 @@ module Pura
19
19
  end
20
20
 
21
21
  def grayscale
22
- new_pixels = String.new(encoding: Encoding::BINARY, capacity: @pixels.bytesize)
22
+ new_pixels = String.new(encoding: Encoding::BINARY)
23
23
  i = 0
24
24
  size = @pixels.bytesize
25
25
  while i < size
@@ -98,7 +98,7 @@ module Pura
98
98
  def rotate90
99
99
  new_w = @height
100
100
  new_h = @width
101
- new_pixels = String.new(encoding: Encoding::BINARY, capacity: new_w * new_h * 3)
101
+ new_pixels = String.new(encoding: Encoding::BINARY)
102
102
 
103
103
  new_h.times do |y|
104
104
  new_w.times do |x|
@@ -111,7 +111,7 @@ module Pura
111
111
  end
112
112
 
113
113
  def rotate180
114
- new_pixels = String.new(encoding: Encoding::BINARY, capacity: @pixels.bytesize)
114
+ new_pixels = String.new(encoding: Encoding::BINARY)
115
115
  (@height - 1).downto(0) do |y|
116
116
  (@width - 1).downto(0) do |x|
117
117
  offset = ((y * @width) + x) * 3
@@ -124,7 +124,7 @@ module Pura
124
124
  def rotate270
125
125
  new_w = @height
126
126
  new_h = @width
127
- new_pixels = String.new(encoding: Encoding::BINARY, capacity: new_w * new_h * 3)
127
+ new_pixels = String.new(encoding: Encoding::BINARY)
128
128
 
129
129
  new_h.times do |y|
130
130
  new_w.times do |x|
@@ -86,7 +86,7 @@ module Pura
86
86
  when :tiff then Pura::Tiff.decode(path)
87
87
  when :ico then Pura::Ico.decode(path)
88
88
  when :webp
89
- raise ArgumentError, "WebP support not available" unless defined?(Pura::Webp)
89
+ raise ArgumentError, "WebP support requires the pura-webp gem" unless defined?(Pura::Webp)
90
90
 
91
91
  Pura::Webp.decode(path)
92
92
  else
@@ -114,7 +114,7 @@ module Pura
114
114
  ico_img = Pura::Ico::Image.new(image.width, image.height, image.pixels)
115
115
  Pura::Ico.encode(ico_img, path)
116
116
  when :webp
117
- raise ArgumentError, "WebP encoding not available" unless defined?(Pura::Webp)
117
+ raise ArgumentError, "WebP support requires the pura-webp gem" unless defined?(Pura::Webp)
118
118
 
119
119
  webp_img = Pura::Webp::Image.new(image.width, image.height, image.pixels)
120
120
  Pura::Webp.encode(webp_img, path, **options)
@@ -1,50 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- begin
3
+ # Only define railtie if Rails is available
4
+ if defined?(Rails)
4
5
  require "rails/railtie"
5
- rescue LoadError
6
- # Rails is not available, skip railtie functionality
7
- return
8
- end
9
6
 
10
- module Pura
11
- module Image
12
- class Railtie < Rails::Railtie
13
- initializer "pura_image.set_variant_processor", before: "active_storage.configs" do |app|
14
- app.config.active_storage.variant_processor = :pura
15
- end
7
+ module Pura
8
+ module Image
9
+ class Railtie < Rails::Railtie
10
+ initializer "pura_image.set_variant_processor", before: "active_storage.configs" do |app|
11
+ app.config.active_storage.variant_processor = :pura
12
+ end
16
13
 
17
- initializer "pura_image.patch_active_storage_variation" do
18
- ActiveSupport.on_load(:active_storage_blob) do
19
- require "image_processing/pura"
14
+ initializer "pura_image.patch_active_storage_variation" do
15
+ ActiveSupport.on_load(:active_storage_blob) do
16
+ require "image_processing/pura"
20
17
 
21
- variation_patch = Module.new do
22
- private
18
+ variation_patch = Module.new do
19
+ private
23
20
 
24
- def transformer
25
- if ActiveStorage.variant_processor == :pura && ActiveStorage.variant_transformer.nil?
26
- @pura_transformer ||= begin
27
- klass = Class.new(ActiveStorage::Transformers::ImageProcessingTransformer) do
28
- private
21
+ def transformer
22
+ if ActiveStorage.variant_processor == :pura && ActiveStorage.variant_transformer.nil?
23
+ @pura_transformer ||= begin
24
+ klass = Class.new(ActiveStorage::Transformers::ImageProcessingTransformer) do
25
+ private
29
26
 
30
- def processor
31
- ImageProcessing::Pura
27
+ def processor
28
+ ImageProcessing::Pura
29
+ end
32
30
  end
33
- end
34
31
 
35
- klass.new(transformations.except(:format))
32
+ klass.new(transformations.except(:format))
33
+ end
34
+ else
35
+ super
36
36
  end
37
- else
38
- super
39
37
  end
40
38
  end
41
- end
42
39
 
43
- unless ActiveStorage::Variation.ancestors.include?(variation_patch)
44
- ActiveStorage::Variation.prepend(variation_patch)
40
+ unless ActiveStorage::Variation.ancestors.include?(variation_patch)
41
+ ActiveStorage::Variation.prepend(variation_patch)
42
+ end
45
43
  end
46
44
  end
47
45
  end
48
46
  end
49
47
  end
50
- end
48
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pura
4
4
  module Image
5
- VERSION = "0.2.2"
5
+ VERSION = "0.2.5"
6
6
  end
7
7
  end
data/lib/pura-image.rb CHANGED
@@ -9,7 +9,7 @@ require "pura-ico"
9
9
  begin
10
10
  require "pura-webp"
11
11
  rescue LoadError
12
- # pura-webp is optional
12
+ # pura-webp is optional — install the gem to enable WebP support.
13
13
  end
14
14
 
15
15
  require_relative "pura/image/version"
data/pura-image.gemspec CHANGED
@@ -13,12 +13,12 @@ Gem::Specification.new do |spec|
13
13
  "with image_processing gem compatible API for Rails Active Storage."
14
14
  spec.homepage = "https://github.com/komagata/pura-image"
15
15
  spec.license = "MIT"
16
- spec.required_ruby_version = ">= 3.0.0"
16
+ spec.required_ruby_version = ">= 3.2.0"
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
19
  spec.metadata["source_code_uri"] = spec.homepage
20
20
 
21
- spec.files = Dir["lib/**/*.rb"] + ["pura-image.gemspec", "Gemfile", "Rakefile", "README.md", "LICENSE"]
21
+ spec.files = Dir["lib/**/*.rb"] + ["test/fixtures/test_64x64.jpg"] + ["pura-image.gemspec", "Gemfile", "Rakefile", "README.md", "LICENSE"]
22
22
 
23
23
  spec.add_dependency "pura-jpeg", "~> 0.1"
24
24
  spec.add_dependency "pura-png", "~> 0.1"
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "pura-gif", "~> 0.1"
27
27
  spec.add_dependency "pura-tiff", "~> 0.1"
28
28
  spec.add_dependency "pura-ico", "~> 0.1"
29
-
30
- spec.add_development_dependency "image_processing", "~> 1.2"
29
+ spec.add_dependency "pura-webp", "~> 0.2"
30
+ spec.add_dependency "image_processing", "~> 1.2"
31
31
  spec.add_development_dependency "minitest", "~> 5.0"
32
32
  spec.add_development_dependency "rake", "~> 13.0"
33
33
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pura-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - komagata
@@ -93,6 +93,20 @@ dependencies:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0.1'
96
+ - !ruby/object:Gem::Dependency
97
+ name: pura-webp
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.2'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.2'
96
110
  - !ruby/object:Gem::Dependency
97
111
  name: image_processing
98
112
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +114,7 @@ dependencies:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
116
  version: '1.2'
103
- type: :development
117
+ type: :runtime
104
118
  prerelease: false
105
119
  version_requirements: !ruby/object:Gem::Requirement
106
120
  requirements:
@@ -154,6 +168,7 @@ files:
154
168
  - lib/pura/image/railtie.rb
155
169
  - lib/pura/image/version.rb
156
170
  - pura-image.gemspec
171
+ - test/fixtures/test_64x64.jpg
157
172
  homepage: https://github.com/komagata/pura-image
158
173
  licenses:
159
174
  - MIT
@@ -167,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
182
  requirements:
168
183
  - - ">="
169
184
  - !ruby/object:Gem::Version
170
- version: 3.0.0
185
+ version: 3.2.0
171
186
  required_rubygems_version: !ruby/object:Gem::Requirement
172
187
  requirements:
173
188
  - - ">="