diff --git a/composer.json b/composer.json
index 6b583a0..897a085 100644
--- a/composer.json
+++ b/composer.json
@@ -4,6 +4,6 @@
   "type": "drupal-module",
   "license": "MIT",
   "require": {
-    "drupal/core": "^10.3 || ^11"
+    "drupal/core": "^10.3 || ^11 || ^12"
   }
 }
diff --git a/src/Hook/WritealtHooks.php b/src/Hook/WritealtHooks.php
new file mode 100644
index 0000000..0a31745
--- /dev/null
+++ b/src/Hook/WritealtHooks.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Drupal\writealt\Hook;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Entity\EntityFormInterface;
+use Drupal\Core\Url;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+/**
+ * Hook implementations for writealt.
+ */
+class WritealtHooks
+{
+    use StringTranslationTrait;
+    /**
+     * @file
+     * Hooks for the WriteAlt module.
+     */
+    /**
+     * Implements hook_help().
+     */
+    #[Hook('help')]
+    public function help($route_name, $route_match)
+    {
+        if ($route_name === 'help.page.writealt') {
+            return '<p>' . $this->t('WriteAlt generates localized alt text for Drupal Media image fields and optimizes existing image files in place.') . '</p>';
+        }
+    }
+    /**
+     * Implements hook_theme().
+     */
+    #[Hook('theme')]
+    public function theme($existing, $type, $theme, $path)
+    {
+        return [
+            'writealt_dashboard' => [
+                'variables' => [
+                ],
+                'template' => 'writealt-dashboard',
+                'path' => $path . '/templates',
+            ],
+        ];
+    }
+}
diff --git a/src/Service/AssetManager.php b/src/Service/AssetManager.php
index db6005c..1169e72 100644
--- a/src/Service/AssetManager.php
+++ b/src/Service/AssetManager.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\writealt\Service;
 
+use Drupal\Core\File\FileExists;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\File\FileUrlGeneratorInterface;
@@ -79,7 +80,7 @@ final class AssetManager {
     if ($candidate === NULL || strlen($candidate) >= strlen($original)) {
       return ['optimized' => FALSE, 'original_bytes' => strlen($original), 'optimized_bytes' => strlen($original)];
     }
-    $this->fileSystem->saveData($candidate, $uri, FileSystemInterface::EXISTS_REPLACE);
+    $this->fileSystem->saveData($candidate, $uri, FileExists::Replace);
     $file->setSize(strlen($candidate));
     $file->setChangedTime(time());
     $file->save();
@@ -140,7 +141,6 @@ final class AssetManager {
       default => FALSE,
     };
     $output = ob_get_clean();
-    imagedestroy($image);
     return $created && is_string($output) ? $output : NULL;
   }
 
diff --git a/writealt.info.yml b/writealt.info.yml
index 736c221..f587dd3 100644
--- a/writealt.info.yml
+++ b/writealt.info.yml
@@ -2,7 +2,7 @@ name: WriteAlt
 type: module
 description: Generate localized alt text and optimize Drupal Media images with WriteAlt.
 package: Media
-core_version_requirement: ^10.3 || ^11
+core_version_requirement: ^10.3 || ^11 || ^12
 dependencies:
   - drupal:file
   - drupal:image
diff --git a/writealt.module b/writealt.module
index c8a808d..1fcdea4 100644
--- a/writealt.module
+++ b/writealt.module
@@ -1,5 +1,11 @@
 <?php
 
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\writealt\Hook\WritealtHooks;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Entity\EntityFormInterface;
+use Drupal\Core\Url;
+
 /**
  * @file
  * Hooks for the WriteAlt module.
@@ -8,10 +14,9 @@
 /**
  * Implements hook_help().
  */
+#[LegacyHook]
 function writealt_help($route_name, $route_match) {
-  if ($route_name === 'help.page.writealt') {
-    return '<p>' . t('WriteAlt generates localized alt text for Drupal Media image fields and optimizes existing image files in place.') . '</p>';
-  }
+  return \Drupal::service(WritealtHooks::class)->help($route_name, $route_match);
 }
 
 /**
@@ -26,30 +31,25 @@ function writealt_page_attachments(array &$attachments) {
 /**
  * Implements hook_theme().
  */
+#[LegacyHook]
 function writealt_theme($existing, $type, $theme, $path) {
-  return [
-    'writealt_dashboard' => [
-      'variables' => [],
-      'template' => 'writealt-dashboard',
-      'path' => $path . '/templates',
-    ],
-  ];
+  return \Drupal::service(WritealtHooks::class)->theme($existing, $type, $theme, $path);
 }
 
 /**
  * Attach the upload controls to Drupal Media entity forms.
  */
-function writealt_form_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+function writealt_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
   $form_object = $form_state->getFormObject();
   $current_path = \Drupal::service('path.current')->getPath();
-  $is_media_entity_form = $form_object instanceof \Drupal\Core\Entity\EntityFormInterface && $form_object->getEntity()->getEntityTypeId() === 'media';
+  $is_media_entity_form = $form_object instanceof EntityFormInterface && $form_object->getEntity()->getEntityTypeId() === 'media';
   $is_media_upload_form = str_contains(strtolower((string) $form_id), 'media') || str_starts_with($current_path, '/admin/content/media');
   if (!$is_media_entity_form && !$is_media_upload_form) {
     return;
   }
   $form['#attached']['library'][] = 'writealt/upload';
   $form['#attached']['drupalSettings']['writealtUpload'] = [
-    'uploadUrl' => \Drupal\Core\Url::fromRoute('writealt.upload', ['operation' => 'generate_file'])->toString(),
+    'uploadUrl' => Url::fromRoute('writealt.upload', ['operation' => 'generate_file'])->toString(),
     'csrfToken' => \Drupal::service('csrf_token')->get('writealt.upload'),
   ];
 }
diff --git a/writealt.services.yml b/writealt.services.yml
index 4848428..970208e 100644
--- a/writealt.services.yml
+++ b/writealt.services.yml
@@ -5,3 +5,7 @@ services:
   writealt.asset_manager:
     class: Drupal\writealt\Service\AssetManager
     arguments: ['@entity_type.manager', '@file_system', '@state', '@file_url_generator', '@current_user', '@logger.factory']
+
+  Drupal\writealt\Hook\WritealtHooks:
+    class: Drupal\writealt\Hook\WritealtHooks
+    autowire: true
