fast_resize 1.0.6 → 1.0.7

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: 14983960ef084b0d1a96d5604f5dbacee46cd40d7de4e550d35ba9a25ec06d57
4
- data.tar.gz: 9cd422af955f4a0c13306630bb5c34fbe866572ee63591bad2ce7f55d2b64543
3
+ metadata.gz: d03efddfcfeab683e99d511f12e73df68959d59f3f34e1259241c8df4adfb91b
4
+ data.tar.gz: a8a996f19ef3acb6c3011c87eebb0eed780e1b96bf45c804f041683f9be4b545
5
5
  SHA512:
6
- metadata.gz: ae758f3390bb46a426084052960c8059092b668d1fa711b701e4dbd2251a2c73005c439bd873bc1e295f99ab07f029e2041b2e34b35c3bbe7ff3d4004d7c83f7
7
- data.tar.gz: 14ac138fd3adf8e44a60d656c283243df42a7fd16ccc541f79b396553a20b6cd622c38f553373dd2e8d8b600e8bda9561ae8065c3ddedcb96bb30e180ef4c9bc
6
+ metadata.gz: fbf0079db596efdada86619be5f9f13fb0bc0138119abe62e7822385d68f6b688fd51886ea0870552ecb7bcb6ac325fac5fccd284de3c3f596d8c75fda3af7b6
7
+ data.tar.gz: 3a423a80dd6ad3534845306aae1ee804cf7ee4a4254ce1b88e38a2f5de66ef5042a3c12d2b60051f3a4728b28210fac50ed7f6c131c4e71ba958399a2c1dd710
data/README.md CHANGED
@@ -257,6 +257,9 @@ fast_resize input.jpg output.jpg 800 600
257
257
  # Batch resize all images in directory
258
258
  fast_resize batch input_dir/ output_dir/ --width 800
259
259
 
260
+ # Batch resize specific files (from stdin, NULL-separated)
261
+ printf 'photo1.jpg\0photo2.jpg\0photo3.jpg' | fast_resize batch --stdin output_dir/ -w 800
262
+
260
263
  # Convert format (JPG → PNG)
261
264
  fast_resize input.jpg output.png 800
262
265
  ```
@@ -279,13 +282,17 @@ FastResize.resize('input.jpg', 'output.jpg',
279
282
  filter: :catmull_rom
280
283
  )
281
284
 
282
- # Batch resize (multi-threaded)
283
- files = Dir['images/*.jpg']
285
+ # Batch resize - all images in directory
286
+ result = FastResize.batch_resize('images/', 'output/', width: 800)
287
+ puts "Processed: #{result[:success]}/#{result[:total]}"
288
+
289
+ # Batch resize - specific files only
290
+ files = ['photo1.jpg', 'photo2.jpg', 'photo3.jpg']
284
291
  result = FastResize.batch_resize(files, 'output/', width: 800)
285
292
  puts "Processed: #{result[:success]}/#{result[:total]}"
286
293
 
287
294
  # Maximum speed mode (uses more RAM)
288
- FastResize.batch_resize(files, 'output/',
295
+ FastResize.batch_resize('images/', 'output/',
289
296
  width: 800,
290
297
  max_speed: true
291
298
  )
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.6
1
+ 1.0.7
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastResize
4
- VERSION = "1.0.6"
4
+ VERSION = "1.0.7"
5
5
  end
@@ -158,7 +158,7 @@ module FastResize
158
158
 
159
159
  # Batch resize images to a directory with same options
160
160
  #
161
- # @param input_paths [Array<String>] Array of input image paths
161
+ # @param input [String, Array<String>] Input directory path OR array of input image paths
162
162
  # @param output_dir [String] Output directory
163
163
  # @param options [Hash] Resize options plus batch options
164
164
  # @option options [Integer] :threads Number of threads (default: auto)
@@ -166,12 +166,16 @@ module FastResize
166
166
  # @option options [Boolean] :max_speed Enable pipeline mode (default: false)
167
167
  # @return [Hash] Result with :total, :success, :failed, :errors
168
168
  #
169
- # @example Batch resize
170
- # files = Dir["photos/*.jpg"]
171
- # result = FastResize.batch_resize(files, "thumbnails/", width: 300)
169
+ # @example Batch resize from directory
170
+ # result = FastResize.batch_resize("photos/", "thumbnails/", width: 300)
172
171
  # # => { total: 100, success: 100, failed: 0, errors: [] }
173
- def self.batch_resize(input_paths, output_dir, options = {})
174
- raise Error, "Input paths cannot be empty" if input_paths.nil? || input_paths.empty?
172
+ #
173
+ # @example Batch resize specific files
174
+ # files = ["photo1.jpg", "photo2.jpg", "photo3.jpg"]
175
+ # result = FastResize.batch_resize(files, "thumbnails/", width: 300)
176
+ # # => { total: 3, success: 3, failed: 0, errors: [] }
177
+ def self.batch_resize(input, output_dir, options = {})
178
+ raise Error, "Input cannot be empty" if input.nil? || (input.respond_to?(:empty?) && input.empty?)
175
179
  raise Error, "Output directory cannot be empty" if output_dir.nil? || output_dir.empty?
176
180
 
177
181
  # Create output directory if it doesn't exist
@@ -180,29 +184,59 @@ module FastResize
180
184
 
181
185
  cli_path = Platform.find_binary
182
186
 
183
- # Create temp file with input paths for batch mode
184
- require 'tempfile'
185
- temp_dir = Tempfile.new(['fastresize_batch', ''])
186
- temp_dir_path = temp_dir.path
187
- temp_dir.close
188
- temp_dir.unlink
187
+ if input.is_a?(String)
188
+ batch_resize_folder(cli_path, input, output_dir, options)
189
+ elsif input.is_a?(Array)
190
+ batch_resize_files(cli_path, input, output_dir, options)
191
+ else
192
+ raise Error, "Input must be a directory path (String) or array of file paths (Array)"
193
+ end
194
+ end
195
+
196
+ private
197
+
198
+ def self.batch_resize_folder(cli_path, input_dir, output_dir, options)
199
+ raise Error, "Input directory not found: #{input_dir}" unless File.directory?(input_dir)
189
200
 
190
- # Copy input files to temp directory (simulate batch input)
191
- # Actually, use the batch command directly
192
201
  args = ['batch']
193
202
  args += build_batch_args(options)
194
-
195
- # Get the input directory from the first file
196
- input_dir = File.dirname(input_paths.first)
197
203
  args << input_dir
198
204
  args << output_dir
199
205
 
200
206
  output = `#{cli_path} #{args.map { |a| "'#{a}'" }.join(' ')} 2>&1`
201
207
  success = $?.success?
202
208
 
203
- # Parse output
209
+ parse_batch_result(output, success, nil)
210
+ end
211
+
212
+ def self.batch_resize_files(cli_path, input_paths, output_dir, options)
213
+ require 'open3'
214
+
215
+ input_paths.each do |path|
216
+ raise Error, "Input file not found: #{path}" unless File.exist?(path)
217
+ end
218
+
219
+ args = ['batch', '--stdin']
220
+ args += build_batch_args(options)
221
+ args << output_dir
222
+
223
+ output = ""
224
+ success = false
225
+
226
+ Open3.popen3(cli_path, *args) do |stdin, stdout, stderr, wait_thr|
227
+ input_paths.each { |path| stdin.write("#{path}\0") }
228
+ stdin.close
229
+
230
+ output = stdout.read + stderr.read
231
+ success = wait_thr.value.success?
232
+ end
233
+
234
+ parse_batch_result(output, success, input_paths.length)
235
+ end
236
+
237
+ def self.parse_batch_result(output, success, expected_total)
204
238
  result = {
205
- total: input_paths.length,
239
+ total: expected_total || 0,
206
240
  success: 0,
207
241
  failed: 0,
208
242
  errors: []
@@ -210,6 +244,9 @@ module FastResize
210
244
 
211
245
  if success
212
246
  # Parse success/failed from output
247
+ if output =~ /Processing (\d+) images/
248
+ result[:total] = $1.to_i if expected_total.nil?
249
+ end
213
250
  if output =~ /(\d+) success/
214
251
  result[:success] = $1.to_i
215
252
  end
@@ -217,13 +254,15 @@ module FastResize
217
254
  result[:failed] = $1.to_i
218
255
  end
219
256
  else
220
- result[:failed] = input_paths.length
257
+ result[:failed] = result[:total]
221
258
  result[:errors] << output.strip
222
259
  end
223
260
 
224
261
  result
225
262
  end
226
263
 
264
+ public
265
+
227
266
  # Batch resize with custom options per image
228
267
  #
229
268
  # @param items [Array<Hash>] Array of items, each with :input, :output, and resize options
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_resize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tran Huu Canh (0xTh3OKrypt)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-02 00:00:00.000000000 Z
11
+ date: 2026-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake