Why is it using a temp file? Is there really no more elegant way to pass around pointers to images than spilling to disk?
You, or rather Claude, are not the first to solve this problem and there are examples of better solutions out there. Since you're willing to let Claude regurgitate other people's work, feel free to look it up yourself or have Claude do it for you.