Implement a program that applies basic image transformations to a batch of images.
You are given a list of input image paths and, for each image, a sequence of operations to apply in order. Support the following operations:
-
grayscale
: convert the image to grayscale.
-
scale(factor)
: multiply both width and height by a positive floating-point scale factor.
-
resize(width, height)
: resize the image to the exact target dimensions.
Part 1
Write a function that processes a small batch of images correctly and saves the transformed results.
Example function shape:
process_images(tasks: list[ImageTask], output_dir: str) -> list[str]
Where each ImageTask contains:
-
input_path
: path to the source image
-
operations
: ordered list of operations such as
grayscale
,
scale(0.5)
, or
resize(200, 300)
The function should return the output paths in the same order as the input tasks.
Part 2
Now assume the images are very large and the batch size is also large. The interviewer asks you to improve performance on a multi-core machine.
Update your approach so that:
-
multiple images can be processed in parallel,
-
output ordering is preserved,
-
a failure in one task does not corrupt other results,
-
the design is appropriate for CPU-heavy image processing.
You may use a standard Python imaging library such as Pillow.