code: def get_orientation_correction(
      preview: Path, page_context: PageContext
  ) -> int:
      """Work out orientation correction for each page.
  
      We ask Ghostscript to draw a preview page, which will rasterize with the
      current /Rotate applied, and then ask OCR which way the page is
      oriented. If the value of /Rotate is correct (e.g., a user already
      manually fixed rotation), then OCR will say the page is pointing
      up and the correction is zero. Otherwise, the orientation found by
      OCR represents the clockwise rotation, or the counterclockwise
      correction to rotation.
  
      When we draw the real page for OCR, we rotate it by the CCW correction,
      which points it (hopefully) upright. _graft.py takes care of the orienting
      the image and text layers.
      """
      orient_conf = page_context.plugin_manager.hook.get_ocr_engine().get_orientation(
          preview, page_context.options
      )
  
      correction = orient_conf.angle % 360
      log.info(describe_rotation(page_context, orient_conf, correction))
      if (
          orient_conf.confidence
          >= page_context.options.rotate_pages_threshold
          and correction != 0
      ):
          return correction
  
      return 0
  
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 12 for calling a global function with example usage: get_orientation_correction(preview, page_context) and returns: int, correction