code: def create_ocr_image(image: Path, page_context: PageContext) -> Path:
      """Create the image we send for OCR.
  
      Might not be the same as the display image depending on preprocessing.
      This image will never be shown to the user.
      """
      output_file = page_context.get_path("ocr.png")
      options = page_context.options
      with Image.open(image) as im:
          log.debug("resolution %r", im.info["dpi"])
  
          if not options.force_ocr:
              # Do not mask text areas when forcing OCR, because we need to OCR
              # all text areas
              mask = None  # Exclude both visible and invisible text from OCR
              if options.redo_ocr:
                  mask = (
                      True  # Mask visible text, but not invisible text
                  )
  
              draw = ImageDraw.ImageDraw(im)
              for textarea in page_context.pageinfo.get_textareas(
                  visible=mask, corrupt=None
              ):
                  # Calculate resolution based on the image size and page dimensions
                  # without regard whatever resolution is in pageinfo (may differ or
                  # be None)
                  bbox = [float(v) for v in textarea]
                  xyscale = tuple(
                      float(coord) / 72.0 for coord in im.info["dpi"]
                  )
                  pixcoords = (
                      bbox[0] * xyscale[0],
                      im.height - bbox[3] * xyscale[1],
                      bbox[2] * xyscale[0],
                      im.height - bbox[1] * xyscale[1],
                  )
                  log.debug("blanking %r", pixcoords)
                  draw.rectangle(pixcoords, fill="white")
                  # draw.rectangle(pixcoords, outline='pink')
  
          filter_im = page_context.plugin_manager.hook.filter_ocr_image(
              page=page_context, image=im
          )
          if filter_im is not None:
              im = filter_im
  
          # Pillow requires integer DPI
          dpi = tuple(round(coord) for coord in im.info["dpi"])
          im.save(output_file, dpi=dpi)
      return output_file
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import sys
  from collections.abc import Iterable, Iterator, Sequence
  from contextlib import suppress
  from pathlib import Path
  from shutil import copyfileobj, copystat
  from typing import Any, BinaryIO, TypeVar, cast
  import img2pdf
  import pikepdf
  from PIL import Image, ImageColor, ImageDraw
  from ocrmypdf._concurrent import Executor
  from ocrmypdf._exec import unpaper
  from ocrmypdf._jobcontext import PageContext, PdfContext
  from ocrmypdf._metadata import repair_docinfo_nuls
  from ocrmypdf.exceptions import DigitalSignatureError, DpiError, EncryptedPdfError, InputFileError, PriorOcrFoundError, TaggedPDFError, UnsupportedImageFormatError
  from ocrmypdf.helpers import IMG2PDF_KWARGS, Resolution, safe_symlink
  from ocrmypdf.hocrtransform import DebugRenderOptions, HocrTransform
  from ocrmypdf.hocrtransform._font import Courier
  from ocrmypdf.pdfa import generate_pdfa_ps
  from ocrmypdf.pdfinfo import Colorspace, Encoding, PageInfo, PdfInfo
  from ocrmypdf.pluginspec import OrientationConfidence
label_desc: Use image node_id 19 for calling a global function with example usage: create_ocr_image(image, page_context) and returns: output_file