You are building a batch image-processing utility.
Implement a function that receives a list of jobs. Each job contains:
-
input_path
: the source image file
-
output_path
: where to write the processed image
-
operations
: an ordered list of image transformations
Support these operations:
-
grayscale
— convert the image to grayscale.
-
scale(f)
— multiply both width and height by a positive scaling factor
f
.
-
resize(w, h)
— resize the image to exactly
w x h
pixels.
For each job, load the image, apply the operations in order, and save the final result to output_path.
Follow-up:
-
First, implement a correct solution for a small number of images.
-
Then improve the implementation for a very large batch. Assume image transformations are CPU-intensive and that jobs are independent. Use process-based parallelism to increase throughput, while still returning one result record per input job and handling per-file failures without stopping the entire batch.
Explain any important design choices, such as worker-count selection, memory considerations, and how you would preserve correctness while improving performance.